a guest Jul 24th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- /* 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);
- // get category term info.
- $term_link = get_term_link( $first_cat->slug, $first_cat->taxonomy );
- echo "<a href='".$term_link."'>".$first_cat->name."</a>";
RAW Paste Data