WordPress.org

Ready to get started?Download WordPress

Forums

parent ,child category help (11 posts)

  1. xinfo
    Member
    Posted 7 years ago #

    Hii

    i want to display only parent category when some one enter in the any parent category then it should show child category of the that parent category if present . do any trik is there

    i just stuck here

    <?php wp_list_cats('sort_column=name&child_of=id'); ?>

  2. soulseed
    Member
    Posted 7 years ago #

    solution can be found at:

    http://codex.wordpress.org/Template_Tags/wp_list_cats
    or simply add &children=o into the php

  3. xinfo
    Member
    Posted 7 years ago #

    <?php wp_list_cats('sort_column=name&children=o'); ?>

    do you mena some thing like this above code is right ?

  4. moshu
    Member
    Posted 7 years ago #

    That code will show only the parent categories.
    It doesn't solve the second part - showing chidren on parent pages.

  5. moshu
    Member
    Posted 7 years ago #

    P.S. But you can always do a search for what you are looking for...
    http://wordpress.org/search/display+children+cat?forums=1

  6. xinfo
    Member
    Posted 7 years ago #

    thank you moshu

    from the search i got below code work for me fine but in the home page it don't show any categoty but when i reach any top level category it show child category any solution

    <?php wp_list_cats('sort_column=id&optioncount=0&
    use_desc_for_title=0&child_of=' . get_query_var('cat')); ?>

  7. moshu
    Member
    Posted 7 years ago #

    Probably you have to use some conditional tag(s) - if on the home page show this... if else, show something else.
    See http://codex.wordpress.org/Conditional_Tags

  8. xinfo
    Member
    Posted 7 years ago #

    sorry to irretate you people again

    i applied below code i get unexpected T_ELSEIF

    <?wp_list_cats('sort_column=id&optioncount=0&
    use_desc_for_title=0&child_of=' . get_query_var('cat'));
    echo "";
    elseif (wp_list_category()) ?>

  9. moshu
    Member
    Posted 7 years ago #

    I am not a coder but that will not work, of course.
    Read again and again the conditionals, especially the Working examples and the Variable sidebar content.

  10. xinfo
    Member
    Posted 7 years ago #

    same here moshu even i am not coder so i am not able to fil this section hope some one solve this issue

  11. moshu
    Member
    Posted 7 years ago #

    I am not sure it will work, I am just copying from the Codex:

    <?php
    // let's generate info appropriate to the page being displayed
    if (is_home()) {
    // we're on the home page, so let's show a list of all top-level categories
    echo "<ul>"; wp_list_cats('optionall=0&sort_column=name&list=1&children=0');
    echo "</ul>";
    } elseif (is_category()) {
    // we're looking at a single category view, so let's show _children categories
    echo "<ul>";
    wp_list_cats('sort_column=id&optioncount=0&
    use_desc_for_title=0&child_of=' . get_query_var('cat'));
    echo "</ul>";
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags