Wordpress - List all the post's categories with custom code in the single page -
Wordpress - List all the post's categories with custom code in the single page -
first of it's supposed used in single page. after single post want display categories post belongs to.
the basic code <?php the_category(' | '); ?>
outputs simple link. have <?php echo get_the_category_list(); ?>
outputs more specific code (http://codex.wordpress.org/function_reference/get_the_category_list):
<ul class="post-categories"> <li> <a href="http://myblog.com/category/business" title="view posts in business" rel="category tag">business</a> </li> </ul>
however need decompose code. example, want <a>
tag before <li>
tag. i've got code want, it's supposed display categories available in page, is:
<?php $categories = get_categories(); foreach($categories $category) { ?> <a href="<?php echo get_category_link($category->cat_id); ?>"><li><?php echo $category->name ?> <span class="lower">(<?php echo $category->count ?>)</span></li></a> <?php } ?>
any thought how can create work?
thanks!
you can utilize get_the_category() homecoming category objects can loop , them want.
$category = get_the_category( /* $post_id */ ); print_r($category); foreach($category $cat) { ?> <a href="<?php echo get_category_link( $cat->term_id ); ?>"><?php echo $cat->name; ?></a> <?php }
wordpress categories
Comments
Post a Comment