SHARE
TWEET

Untitled

a guest Jul 24th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /* Useful code snippet if you want to display the category title on top
  3.  * of a featured image on a list of post.
  4.  * If a post is in more than one category, this snippet
  5.  * selects the first one. If no cateogry is set, the default category appears.
  6.  */
  7.  
  8.         $post_categories = wp_get_post_categories( $post->ID );
  9.         // get first category id
  10.         $first_cat = get_category($post_categories[0]);
  11.         // get category term info.
  12.         $term_link = get_term_link( $first_cat->slug, $first_cat->taxonomy );
  13.  
  14.         echo "<a href='".$term_link."'>".$first_cat->name."</a>";
  15. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top