本文整理汇总了PHP中get_category_link函数的典型用法代码示例。如果您正苦于以下问题:PHP get_category_link函数的具体用法?PHP get_category_link怎么用?PHP get_category_link使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_category_link函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: inti_get_categories_meta
function inti_get_categories_meta($args = '')
{
$count = 0;
$categories_list = '';
$categories = get_the_category();
foreach ($categories as $category) {
$count++;
if ($args['show_uncategorized']) {
$categories_list .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__('View all posts in %s', 'inti'), $category->name) . '"><span class="label category">' . $category->name . '</span></a>';
if ($count != count($categories)) {
$categories_list .= ' ';
//separator
}
} else {
if ($category->slug != 'uncategorized' || $category->name != 'Uncategorized') {
$categories_list .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__('View all posts in %s', 'inti'), $category->name) . '"><span class="label category">' . $category->name . '</span></a>';
if ($count != count($categories)) {
$categories_list .= ' ';
//separator
}
}
}
}
return $categories_list;
}
示例2: CTF_snippet
function CTF_snippet($atts)
{
extract(shortcode_atts(array('category' => '', 'link' => '', 'date' => '', 'dofollow' => FALSE), $atts));
global $post;
$snippet = "{$postid}<div class=\"ctf-snippet\">";
$snippet .= "<span class=\"ctf-title\">CTF:</span> <span class=\"ctf-value\">";
if (empty($category)) {
//Default category (1st category)
$snippet .= "<a href=\"" . get_category_link(get_the_category($post->ID)[0]->cat_ID) . "\" rel=\"category tag\">" . get_the_category($post->ID)[0]->name . "</a>";
} else {
$snippet .= $category;
}
$snippet .= "</span>";
$snippet .= "<br />";
$snippet .= "<span class=\"ctf-title\">Link to challenge:</span> <span class=\"ctf-value\">";
//Generate link
if (!empty($link)) {
$snippet .= "<a href=\"{$link}\" rel=\"external";
if (!$dofollow) {
$snippet .= " nofollow";
}
$pu = parse_url($link);
$link_base = $pu["scheme"] . "://" . $pu["host"];
$snippet .= "\">{$link_base}</a>";
$snippet .= "<img class=\"external_url\" src=\"" . get_stylesheet_directory_uri() . "/images/external-link.png\" />";
} else {
$snippet .= "N/A";
}
$snippet .= "</span><br />";
//Date of completion
$snippet .= "<span class=\"ctf-title\">Date Completed:</span> <span class=\"ctf-value\">{$date}</span>";
$snippet .= "</div>";
return $snippet;
}
示例3: the_breadcrumb
function the_breadcrumb()
{
global $post;
if (!is_home()) {
echo '<div class="main_breadcrum"><p><a href="'. get_option('home') .'"> Home </a> > ';
if ( is_category() || is_single() ) {
foreach( ( get_the_category() ) as $category ) {
if ( $category->cat_name != 'Slider' ) {
echo '<a href="'. get_category_link( $category->term_id ) .'" title="'. $category->name .'" ' . '>'. $category->name .'</a> ';
}
}
echo '</p></div>';
} elseif ( is_page() ) {
if( $post->post_parent ){
$result = get_post_ancestors( $post->ID );
$title = get_the_title();
$output = '';
$anc = array_reverse( $result );
foreach ( $anc as $ancestor ) {
$output .= '<a href="'. get_permalink( $ancestor ) .'" title="'. get_the_title( $ancestor ) .'">'.get_the_title( $ancestor ) .'</a> > ';
}
echo $output;
echo '<strong title="'. $title .'"> '. $title .'</strong></p></div>';
} else {
echo '<strong> '. get_the_title() .'</strong></p></div>';
}
}
}
}
示例4: widget
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
* @since 1.0.0
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
function widget($args, $instance)
{
// Extract args
extract($args, EXTR_SKIP);
$category_id = empty($instance['category_id']) ? 1 : $instance['category_id'];
$use_cat_title = empty($instance['use_cat_title']) ? 0 : $instance['use_cat_title'];
$hide_empty_cats = empty($instance['hide_empty_cats']) ? 0 : $instance['hide_empty_cats'];
$show_post_count = empty($instance['show_post_count']) ? 0 : $instance['show_post_count'];
$title_link = empty($instance['title_link']) ? 0 : $instance['title_link'];
if ($use_cat_title) {
$title = apply_filters('widget_title', get_cat_name($category_id), $instance, $this->id_base);
} else {
$title = apply_filters('widget_title', empty($instance['title']) ? __('Sub Categories', 'wpsp') : $instance['title'], $instance, $this->id_base);
}
$no_sub_text = '<p>' . __('No sub-categories', 'wpsp') . '</p>';
$subs = wp_list_categories(array('child_of' => $category_id, 'hide_empty' => $hide_empty_cats, 'show_count' => $show_post_count, 'title_li' => null, 'show_option_none' => '', 'echo' => 0));
echo $before_widget;
if ($title_link) {
echo $before_title . '<a href="' . get_category_link($category_id) . '">' . $title . '</a>' . $after_title;
} else {
echo $before_title . $title . $after_title;
}
if (!empty($subs)) {
echo '<ul>' . $subs . '</ul>';
} else {
echo $no_sub_text;
}
echo $after_widget;
return $instance;
}
示例5: loop_category
function loop_category($category)
{
$idObj = get_category_by_slug($category);
$cat_name = $idObj->name;
if ($category === 'news') {
$number = 4;
} else {
$number = 1;
}
$args = array('posts_per_page' => $number, 'category_name' => $category);
$posts_array = get_posts($args);
$length = count($posts_array);
if ($length > 0) {
echo '<a href="' . get_category_link($idObj->cat_ID) . ' " ><h3 class="big-article-title">' . $cat_name . '</h3></a>';
global $post;
foreach ($posts_array as $key => $post) {
setup_postdata($post);
if ($key === 0) {
get_template_part('templates/content', get_post_type() != 'post' ? get_post_type() : get_post_format());
} else {
if ($key === 1) {
echo '<ul class="other-post-list length' . ($length - 1) . '">';
}
get_template_part('templates/content', 'post-intro');
if ($key === $length) {
echo '</ul>';
}
}
}
wp_reset_postdata();
}
}
示例6: widget
function widget($args, $instance)
{
extract($args);
$title = empty($instance['title']) ? '' : $instance['title'];
echo $before_widget;
if ($title) {
echo $before_title . $title . $after_title;
}
?>
<ul class="media-list">
<?php
$args = array('hierarchical' => false, 'pad_counts' => true, 'parent' => 0, 'orderby' => 'count', 'order' => 'DESC');
$topCat = get_categories($args);
foreach ($topCat as $category) {
$attrImg = array('class' => 'pull-left', 'alt' => 'Logo ' . $category->name, 'height' => 40, 'width' => 40, 'title' => $category->name);
echo '<li class="media"><div class="media-left"><a title="' . $category->name . '" class="media-heading" href="' . get_category_link($category->term_id) . '">';
z_taxonomy_image($category->term_id, array(40, 40, true), $attrImg);
echo '</a></div><div class="media-body media-middle">';
echo '<a title="' . $category->name . '" class="media-heading" href="' . get_category_link($category->term_id) . '">' . $category->name . ' <span class="badge">' . $category->count . '</span></a>';
echo '</div></li>';
}
?>
</ul>
<?php
echo $after_widget;
}
示例7: get_category
function get_category()
{
$buffy = '';
//read the post meta to get the custom primary category
$td_post_theme_settings = get_post_meta($this->post->ID, 'td_post_theme_settings', true);
if (!empty($td_post_theme_settings['td_primary_cat'])) {
//we have a custom category selected
$selected_category_obj = get_category($td_post_theme_settings['td_primary_cat']);
} else {
//get one auto
$categories = get_the_category($this->post->ID);
if (!empty($categories[0])) {
if ($categories[0]->name === TD_FEATURED_CAT and !empty($categories[1])) {
$selected_category_obj = $categories[1];
} else {
$selected_category_obj = $categories[0];
}
}
}
if (!empty($selected_category_obj)) {
//@todo catch error here
$buffy .= '<a href="' . get_category_link($selected_category_obj->cat_ID) . '">' . $selected_category_obj->name . '</a>';
}
//return print_r($post, true);
return $buffy;
}
示例8: widget
function widget($args, $instance)
{
extract($args, EXTR_SKIP);
$category_id = empty($instance['category_id']) ? 1 : $instance['category_id'];
$use_cat_title = empty($instance['use_cat_title']) ? 0 : $instance['use_cat_title'];
$hide_empty_cats = empty($instance['hide_empty_cats']) ? 0 : $instance['hide_empty_cats'];
$show_post_count = empty($instance['show_post_count']) ? 0 : $instance['show_post_count'];
$title_link = empty($instance['title_link']) ? 0 : $instance['title_link'];
$excluded = empty($instance['excluded']) ? '' : $instance['excluded'];
$sub_subs = empty($instance['sub_subs']) ? 0 : $instance['sub_subs'];
$dropdown = empty($instance['dropdown']) ? 0 : $instance['dropdown'];
$post_is_parent = empty($instance['post_is_parent']) ? 0 : $instance['post_is_parent'];
$dropdown_text = empty($instance['dropdown_text']) ? __('Select Sub-category', 'sub-categories-widget') : $instance['dropdown_text'];
$list_order = empty($instance['list_order']) ? 0 : $instance['list_order'];
if ($post_is_parent) {
$category = get_the_category();
$category_id = $category ? $category[0]->cat_ID : 1;
}
if ($use_cat_title) {
$title = apply_filters('widget_title', get_cat_name($category_id), $instance, $this->id_base);
} else {
$title = apply_filters('widget_title', empty($instance['title']) ? __('Sub Categories', 'sub-categories-widget') : $instance['title'], $instance, $this->id_base);
}
$parent = $sub_subs == 1 ? 'child_of' : 'parent';
$order = $list_order == 1 ? 'DESC' : 'ASC';
$no_sub_text = '<p>' . __('No sub-categories', 'sub-categories-widget') . '</p>';
$subs = wp_list_categories(array($parent => $category_id, 'hide_empty' => $hide_empty_cats, 'show_count' => $show_post_count, 'exclude' => $excluded, 'title_li' => null, 'show_option_none' => '', 'echo' => 0, 'orderby' => 'ID', 'order' => $order));
if ($post_is_parent == 0 || $post_is_parent == 1 && !empty($subs)) {
echo $before_widget;
if ($title_link) {
echo $before_title . '<a href="' . get_category_link($category_id) . '">' . $title . '</a>' . $after_title;
} else {
echo $before_title . $title . $after_title;
}
if ($dropdown == 0) {
if (!empty($subs)) {
echo '<ul>' . $subs . '</ul>';
} else {
echo $no_sub_text;
}
} else {
$subs = wp_dropdown_categories(array('id' => 'sub-cat-' . $this->number, 'show_option_none' => $dropdown_text, $parent => $category_id, 'hide_empty' => $hide_empty_cats, 'show_count' => $show_post_count, 'exclude' => $excluded, 'hide_if_empty' => true, 'echo' => false, 'orderby' => 'ID', 'order' => $order));
if (!empty($subs)) {
echo $subs;
echo '<script type="text/javascript">
/* <![CDATA[ */
var dropdown' . $this->number . ' = document.getElementById("sub-cat-' . $this->number . '");
function onSubCatChange() {
if (dropdown' . $this->number . '.options[dropdown' . $this->number . '.selectedIndex].value > 0) { location.href = "' . get_option('home') . '?cat="+dropdown' . $this->number . '.options[dropdown' . $this->number . '.selectedIndex].value; }
}
dropdown' . $this->number . '.onchange = onSubCatChange;
/* ]]> */
</script>';
} else {
echo $no_sub_text;
}
}
echo $after_widget;
}
}
示例9: widget
function widget($args, $instance)
{
extract($args);
$c = $instance['count'] ? '1' : '0';
$archive_type = $instance['archive_type'] ? '1' : '0';
$title = apply_filters('widget_title', __('Archives', 'unspoken'));
echo $before_widget;
if ($title) {
echo $before_title . $title . $after_title;
}
if ($archive_type == 0) {
$categories = get_categories();
$output = '<ul>';
foreach ($categories as $category) {
$output .= sprintf('<li><a href="%1$s" title="%2$s">%3$s</a><span>%4$s</span></li>', get_category_link($category->term_id), sprintf(__('View all posts in %s', 'unspoken'), $category->name), $category->name, $c ? $category->count : '');
}
$output .= '</ul>';
} else {
global $wpdb, $wp_locale;
// set limit for list
$archive_limit = 0;
// query
$q = "SELECT YEAR(post_date) AS 'year', MONTH(post_date) AS 'month', COUNT(ID) as post_count " . "FROM {$wpdb->posts} " . "WHERE post_type = 'post' AND post_status = 'publish' " . "GROUP BY month, year " . "ORDER BY post_date DESC" . ($archive_limit == 0 ? '' : ' LIMIT ' . $archive_limit);
// make query for result
$months = $wpdb->get_results($q);
$output = '<ul>';
// looping through result
foreach ($months as $month) {
$output .= sprintf('<li><a href="%1$s">%2$s<span>%3$s</span></a></li>', get_month_link($month->year, $month->month), sprintf(__('%1$s %2$d'), $wp_locale->get_month($month->month), $month->year), $c ? $month->post_count : '');
}
$output .= '</ul>';
}
echo $output;
echo $after_widget;
}
示例10: _meta_data
private function _meta_data($view, $params)
{
$defaults = array('class' => '');
$params = wp_parse_args($params, $defaults);
$content = '';
// Date
$content .= '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '" class="blog_date"><i class="icon-calendar"></i>' . get_the_date('F j, Y') . '</a>';
// Categories
$post_categories = wp_get_post_categories(get_the_ID());
$categories = array();
foreach ($post_categories as $c) {
$cat = get_category($c);
$categories[] = '<a href="' . get_category_link($cat->term_id) . '">' . $cat->name . '</a>';
}
if (count($categories) > 0) {
$content .= '<div class="blog_category"><i class="icon-tag"></i>' . implode(', ', $categories) . '</div>';
}
// Author
$content .= '<span class="blog_author"><i class="icon-user"></i>' . get_the_author() . '</span>';
$post_tags = wp_get_post_tags(get_the_ID());
$tags = array();
foreach ($post_tags as $tag) {
$tags[] = '<a href="' . get_tag_link($tag->term_id) . '">' . $tag->name . '</a>';
}
if (count($tags) > 0) {
$content .= '<div class="blog_category"><i class="icon-tag"></i>' . implode(', ', $tags) . '</div>';
}
return '<div class="' . $params['class'] . '">' . $content . '</div>';
}
示例11: widget
function widget($args, $instance)
{
/* Get title */
$args['title'] = $instance['title'];
/* If empty, default */
if (!$args['title']) {
$args['title'] = 'Popular Categorys';
}
/* Get nnpopularcats */
$args['npopularcats'] = $instance['npopularcats'];
/* If empty, default 10 */
if (!$args['npopularcats']) {
$args['npopularcats'] = 10;
}
/* Get popular cats */
global $wpdb;
$query = "SELECT a.name, a.slug, b.term_id, b.count FROM {$wpdb->term_taxonomy} b\n \t\t\tLEFT JOIN {$wpdb->terms} a\n \t\t\tON b.term_id = a.term_id\n \t\t\tWHERE b.taxonomy = 'category'\n \t\t\tORDER BY b.count DESC\n \t\t\tLIMIT " . $args['npopularcats'];
$get_categories = $wpdb->get_results($query);
// Prepare cats list
$list = '<ul class="popular-category-list">';
foreach ($get_categories as $cat) {
$list .= '<li><a href="' . get_category_link($cat->term_id) . '">' . $cat->name . '</a></li>';
}
$list .= '</ul>';
// Print everything
echo $args['before_widget'] . $args['before_title'] . $args['title'] . $args['after_title'];
echo $list;
echo $args['after_widget'];
}
示例12: run_menu
function run_menu()
{
$Menu = [];
$args = array('orderby' => 'name', 'parent' => 0);
$categories = get_categories($args);
foreach ($categories as $key => $category) {
$children = get_terms($category->taxonomy, array('parent' => $category->term_id, 'hide_empty' => false));
if ($children) {
$genre = $category->name;
$list = '<li class="has-children"><a href="#0">' . $genre . '</a><ul class="is-hidden here"><li class="go-back"><a href="#0">' . $genre . '</a></li><li class="see-all"><a href="' . get_category_link($category->term_id) . '">All ' . $genre . '</a></li>';
$ChildCats = get_categories('child_of=' . $category->cat_ID);
foreach ($ChildCats as $ChildCat) {
$option = '<li><a href="' . get_category_link($ChildCat->term_id) . '">';
$option .= $ChildCat->cat_name;
$option .= '</a></li>';
$list .= $option;
}
$list .= '</ul></li>';
} else {
$list = '<li><a href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></li>';
}
$Menu[] = $list;
}
return $Menu;
//print_r($Menu);
}
示例13: woo_tumblog_category_link
function woo_tumblog_category_link($post_id = 0, $type = 'articles')
{
$category_link = '';
if (get_option('woo_tumblog_content_method') == 'post_format') {
$post_format = get_post_format();
if ($post_format == '') {
$category = get_the_category();
$category_name = $category[0]->cat_name;
// Get the ID of a given category
$category_id = get_cat_ID($category_name);
// Get the URL of this category
$category_link = get_category_link($category_id);
} else {
$category_link = get_post_format_link($post_format);
}
} else {
$tumblog_list = get_the_term_list($post_id, 'tumblog', '', '|', '');
$tumblog_array = explode('|', $tumblog_list);
?>
<?php
$tumblog_items = array('articles' => get_option('woo_articles_term_id'), 'images' => get_option('woo_images_term_id'), 'audio' => get_option('woo_audio_term_id'), 'video' => get_option('woo_video_term_id'), 'quotes' => get_option('woo_quotes_term_id'), 'links' => get_option('woo_links_term_id'));
?>
<?php
// Get the ID of Tumblog Taxonomy
$category_id = $tumblog_items[$type];
$term =& get_term($category_id, 'tumblog');
// Get the URL of Articles Tumblog Taxonomy
$category_link = get_term_link($term, 'tumblog');
}
return $category_link;
}
示例14: render
function render($atts, $content = null)
{
parent::render($atts);
$buffy = '';
extract(shortcode_atts(array('limit' => '6', 'custom_title' => '', 'custom_url' => '', 'hide_title' => '', 'header_color' => ''), $atts));
$cat_args = array('show_count' => true, 'orderby' => 'count', 'hide_empty' => false, 'order' => 'DESC', 'number' => $limit, 'exclude' => get_cat_ID(TD_FEATURED_CAT));
// exclude categories from the demo
if (TD_DEPLOY_MODE == 'demo' or TD_DEPLOY_MODE == 'dev') {
$cat_args['exclude'] = '90, 91, 92, 93 , 94, 95, 96, 97, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 82, 83, 84, 85, 86, 87, 88, 89, 98, ' . get_cat_ID(TD_FEATURED_CAT);
}
$categories = get_categories($cat_args);
// has a limit of 6 by default
$buffy .= '<div class="' . $this->get_block_classes(array('widget', 'widget_categories')) . '">';
$buffy .= $this->get_block_title();
if (!empty($categories)) {
$buffy .= '<ul class="td-pb-padding-side">';
foreach ($categories as $category) {
if (strtolower($category->cat_name) != 'uncategorized') {
$buffy .= '<li><a href="' . get_category_link($category->cat_ID) . '">' . $category->name . '<span class="td-cat-no">' . $category->count . '</span></a></li>';
}
}
$buffy .= '</ul>';
}
$buffy .= '</div> <!-- ./block -->';
return $buffy;
}
示例15: categories
/**
* Get the categories attached to this post
* @return array
*/
public function categories()
{
$categories = get_the_category($this->wp_post);
return array_map(function ($category) {
return (object) array_merge((array) $category, ['url' => get_category_link($category->term_id)]);
}, $categories);
}