WordPress.org

Ready to get started?Download WordPress

Forums

How to show only child category of a parent category in posts? (10 posts)

  1. omerkanipak
    Member
    Posted 7 years ago #

    I have a site with 2 levels of categories. http://www.arkispot.com I have 4 main categories and their children.

    The Structure is like this:

    A
    1
    2
    3
    B
    1
    2
    C
    1
    2
    D
    1
    2

    I want to show separately the child categories of A and B underneath the title without link, and child categories of B and C with links, under each post.

    You can have an example from http://www.arkispot.com but the category ordering is scrambled. I cannot manage the ordering of the child categories.

    How can I do this?

  2. ladydelaluna
    Member
    Posted 7 years ago #

    http://codex.wordpress.org/Template_Tags/wp_list_cats

    Try reading that for the arguments you'll need to use in the code for getting child cats to show up.

  3. manstraw
    Member
    Posted 7 years ago #

    I haven't been able to get the codex for a while now. It's timing out before anything comes up. Not sure if you're having that problem omerkanipak, but if you search these forums, you might find the specific info you need. just search for wp_list_cats. I'm not familiar enough with this to advise from memory.

  4. omerkanipak
    Member
    Posted 7 years ago #

    wp_list_cats might be the solution but I want the children categories to be displayed horizontally, underneath each post in the entry_meta area.

    Currently the code is like this under each post.

    <?php echo ;the_category(',');?>

    This code lists every child category which the post is related without the control of ordering. I would like to control the ordering of the children categories actually. For instance I want the child category of A and D comes first, then the B and C.

  5. ladydelaluna
    Member
    Posted 7 years ago #

    omerkanipak - you mean as in "filed in: cat A cat 3" type stuff under the post titles? oh, this is entirely a different animal.

    and i can get to the codex without hesitation no problem - haven't had any issues with that at all actually.

    http://codex.wordpress.org/The_Loop - check this out for more help with that, if I'm now understanding you correctly. :)

  6. omerkanipak
    Member
    Posted 7 years ago #

    yes, you are right. But I couldn't figure it our from the loop page. I want to print under each post the child categories of the post. In my blog, a post may belong to several child categories of 4 parent categories. I want to show and order the children categories of these 4 parent categories as I wish.For example 2 underneath the title, 2 under the post. I thing get_category tag needs some additional parameters to work this out. Any help will be appreciated :)

  7. Jauhari
    Member
    Posted 7 years ago #

    Wow this function really help full but I need guide how to do this?

    I was success show post only on child, but I want show the child of the categories.

    A
    1
    2
    B
    1
    2
    3

    Then if I click categories A > 1 their will show all post from A1.

    If I click categories A
    The page will show All child of A categories.

    How to add this code?

  8. Jauhari
    Member
    Posted 7 years ago #

    Problem was solved ;)

    Thanks

  9. manstraw
    Member
    Posted 7 years ago #

    What did you do to solve the problem?

  10. Jauhari
    Member
    Posted 7 years ago #

    I use from function from another tread, but I can't remember who is posting (sorry) the function like this


    function cat_is_parent() {
    global $wpdb;
    $grypesagon_cat_title = single_cat_title('', false);
    $parent = $wpdb->get_var("SELECT
    category_parent FROM $wpdb->categories WHERE cat_name = '$grypesagon_cat_title'");
    if ( 0 == $parent ) {
    return true;
    } else {
    return false;
    }
    }

    Then on my category themes I add this code

    <?php
    if ( cat_is_parent() ) {
    // Replace this with the code
    // you want when the category is a parent

    } else {

    // when the category is a child
    // untuk aksi jika
    }
    ?>

    That's all.

    CMIIW.

Topic Closed

This topic has been closed to new replies.

About this Topic