How to grab the first category of a link post in the homepage and insert a link? (2 posts)

  1. wpmhweb
    Posted 4 years ago #

    Hello everyone!
    I am still new in WordPress programming and I was wondering if anyone can help me with this.
    I have list of links of recent posts in the homepage and I would like to add the category link right below the link of each particular link, but I don't know how to do this, could anyone point me in to the right direction?


  2. wpmhweb
    Posted 4 years ago #

    Thank you,
    I was able to answer my own question:

    		$cat = get_the_category(); $cat = $cat[0]; echo '<a class="cat_box" href="' . get_bloginfo('url') . '/category/' . $cat->category_nicename . '">';
    			echo $cat->cat_name;
    			echo  '</a>';

Topic Closed

This topic has been closed to new replies.

About this Topic