Forums

[resolved] How to show only subcategory for a post? Anyone, finally! (4 posts)

  1. pospel
    Member
    Posted 9 months ago #

    Hello.

    This is my last hope, googling and forum searching not helped :(
    Lots of similar questions with no answers.

    Starving for a solution: plugin, hack, php code - anything!

    I need to get and show a child (subcategory) for a post (with path).
    For example, i have post that belong to many categories and subcategories and wish on single-post pages show only one subcategory which post bind to.

    Thanks

  2. stvwlf
    Member
    Posted 9 months ago #

    If a post is in many categories and subcategories and you only want to show one on the single post page, how is the single post page code going to determine which one subcategory you want to show?

  3. pospel
    Member
    Posted 9 months ago #

    By it parent category, afaik, by applying some additional filtering.

    In my case - post is only in subcategories of several parent categories. Think of it, like you have several category groups and you want to know what exact subcategories it bind to within one category group.

    For example, you have categories for car manufacturers (toyota, audi, bmw) and for car types (sports car, minivan, offroad) . On single post page you want to show a link to car manufacturer group which post belong to (i.e. category). So you know, you should look in manufacturer group to retrieve exact manufacturer (i.e. subcategory).

  4. pospel
    Member
    Posted 9 months ago #

    If you want to do something - do it yourself.
    Here is a solution:

    <?php
    foreach((get_the_category()) as $category)
    {
        if ($category->category_parent == "6")
        {
            echo '<a href="' . get_category_link($category->cat_ID) . '">' . $category->cat_name . '</a>';
        }
    }
    ?>

Reply

You must log in to post.

About this Topic