On a template that I’m building, within the single.php I need to have links to the parent category & child category. Each post will only have one parent category & one child category.

My url structure for the post would look like this:

/kia/sportage/kia-sportage-2-0/

The category urls would then look like this:

/category/kia/ and /category/kia/sportage/

so far I’ve used the following code:

<a href="<?php $cat = get_the_category(); $cat = $cat[0]; echo get_category_link($cat->cat_ID); ?>"> <?php $category = get_the_category(); echo $category[0]->cat_name;?></a>

This links to the /category/kia/sportage/ url with the anchor text of Sportage

I also need to create a link to /category/kia/ with the anchor text of Kia, how can this be done?

Thanks in advance
Willem

Read more here: Current Post Parent Category & Child Category Links


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: