• Hi,

    I want to display the name of the child category name but it keeps display both parent and child category name. The code I have now is:

    <?php the_category(‘, ‘) ?>

    Is there any simple way to display only the child category name? Much appreciated. Thanks!

    AD

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello !
    <? $category = get_the_category(); echo $category[0]->cat_name; ?>)
    or
    <? $category = get_the_category(); echo $category[1]->cat_name; ?>)
    if the post have multiple category…

    Thread Starter Agent D

    (@agent-d)

    Thanks for the suggestion. I tried it but it displays only parent category name and not the child category name.

    AD

    Thread Starter Agent D

    (@agent-d)

    Oh, never mind, the second one worked! Thanks for the suggestion!

    AD

    Thread Starter Agent D

    (@agent-d)

    Now I have another problem… If there is any post which has more than one categories assigned WordPress only displays the younger ID number’s title. For example I have one post which is in Illustration (id=5) and painting (id=8), and if you go to the page for Painting the title header is “Illustration”. Any idea how to prevent this?

    Thanks!

    this is a good solution, i was trying to do this myself.

    I have a question, how can I use this to display the category/child category but not as a link?

    To make sourcelab’s multiple-category solution more flexible, try:

    <?php $category = get_the_category(); $last_category = end($category); echo $last_category->cat_name; ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to display only child category name?’ is closed to new replies.