• Hey!

    I’m trying to print out only sub-categories of each post on category archive of my website. The category structure I have is similar to the following

    Parent Category A
    Sub-category A.1
    Sub-category A.2
    Sub-category A.3

    Let’s say a post is filed under Parent Category A and Sub-category A.1 and Sub-category A.3. When the archive of Parent Category A is viewed, this post is shown there too. Now, I would like to print only the sub-categories of this post Sub-category A.1 and Sub-category A.3 after the excerpt of the post. The position doesn’t matter as I can fix that later.

    Anyone could please guide me how I can print out the sub-categories? Any help is much appreciated.

    Thanks.

    Btw, I’m using the following code to print out only parent category of posts. Maybe I can edit and somehow use it for the purpose above? Any idea?

    <?php $category = get_the_category(); $parent = get_cat_name($category[0]->category_parent);
    if (!empty($parent)) {echo ''. $parent; } else { echo ''. $category[0]->cat_name; } ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • From this:

    <?php $category = get_the_category(); $parent = get_cat_name($category[0]->category_parent);
    if (!empty($parent)) {echo ''. $parent; } else { echo ''. $category[0]->cat_name; } ?>

    To this:

    <?php $category = get_the_category(); $parent = get_cat_name($category[0]->category_parent);
    if (!empty($parent)) { echo ''. $category[0]->cat_name; } ?>

    Try that. No promises ??

    Thread Starter ucarmetin

    (@ucarmetin)

    Hej RJGonzalez,

    Thanks for the response. Just tried your proposed code sample and I must say it works. However, it prints out only one sub-category that comes first alphabetically.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display only post sub-categories’ is closed to new replies.