marko krstić

Collections

Archives

Display list of categories that are related to a particular post on your single page

<?php
	$categories = get_the_category();
		if($categories){
			echo '<div>';
			foreach($categories as $category) {
			echo '<span>' . $category->cat_name . '</span>';
		}
	echo '</div>';
}

?>

If you need just parent cagetory

Parrent

  • Child
  • Child
  • Child
<?php
  $perma_cat = get_post_meta($post->ID , '_category_permalink', true);
  if ( $perma_cat != null ) {
    $cat_id = $perma_cat['category'];
    $category = get_category($cat_id);
  } else {
    $categories = get_the_category();
    $category = $categories[0];
  }
  $category_link = get_category_link($category);
  $category_name = $category->name;  
?>                                   
<a href="<?php echo $category_link ?>"><?php echo $category_name ?></a>

Let's Connect

Feel free to reach out for collaborations or just a friendly hello ?
[email protected]
linkedininstagramdribbblefacebook-official