Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Useful code snippet if you want to display the category title on top
- * of a featured image on a list of post.
- * If a post is in more than one category, this snippet
- * selects the first one. If no cateogry is set, the default category appears.
- */
- $post_categories = wp_get_post_categories( $post->ID );
- // get first category id
- $first_cat = get_category($post_categories[0]);
- // get category term info.
- $term_link = get_term_link( $first_cat->slug, $first_cat->taxonomy );
- echo "<a href='".$term_link."'>".$first_cat->name."</a>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement