WordPress.org

Ready to get started?Download WordPress

Forums

List posts within category menu? (11 posts)

  1. mailinator007
    Member
    Posted 2 years ago #

    Hi all!

    Is it possible to list posts within categories with wp_list_categories (or something else).

    I must achieve the following scheme:

    • Category 1
    • Category 2
      • Subcategory 2.1
      • Subcategory 2.2
      • Subcategory 2.3
        • Sub Subcategory 2.3.1 (contain posts, they should not be visible)
        • Sub Subcategory 2.3.2 (contain posts, they should be visible)
          • Post 1 in Sub Subcategory 2.3.2
          • Post 2 in Sub Subcategory 2.3.2

    Also there is a problem that some subcategories should not display their posts, while others should display them.

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    Also there is a problem that some subcategories should not display their posts, while others should display them.

    without this problem,
    you could try the code from my article 'Hierarchical Category List with Post Titles';
    however, this code will not be able to restrict showing posts of only some of the sub-categories.

  3. mailinator007
    Member
    Posted 2 years ago #

    Thank you very much!
    Although I'm not good in PHP, I'll try to modify it :)

  4. mailinator007
    Member
    Posted 2 years ago #

    Small update:
    On line 10, you should use hide_empty=0, instead of hide_empty=false :)

  5. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    thanks for the tip -
    the same would apply to line 32 as well.

    i have updated the post.

  6. mailinator007
    Member
    Posted 2 years ago #

    Of course, line 32 as well :)

    Beside this, output is wrong, I mean its not semantically correct, so I repaired that. You can see my current code at http://pastebin.com/ciQ5CkJg

    At this point, I'm one step from my goal. Maybe you can help me here :)
    At the link above , look for the lines from 35 to 50. For some reason $next2 variable is always empty, even if it is copied code from $next variable.

    What I want to achieve at this part is that loop skip the code for listing posts only if 'category id' (in my case 88) is different from the one I entered.

  7. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    the $cat here parent=' . $cat in code in line 36 of your pastebin

    $next2 = get_categories('orderby=order&hide_empty=0&parent=' . $cat);

    is not the $cat of function process_cat_tree( $cat ) (line 14) as i re-use the variable name in here foreach( $next as $cat ) : (line 23).

    ---
    also, the empty output might possibly be caused by:

    orderby=order is none of the valid parameters:

    http://codex.wordpress.org/Function_Reference/get_categories

    orderby
    (string) Sort categories alphabetically or by unique category ID. The default is sort by Category ID. Valid values:
    id
    name - default
    slug
    count
    term_group

  8. mailinator007
    Member
    Posted 2 years ago #

    Yeah, I know. It is from 'My category order' plugin.
    Even after I delete plugin and remove 'orderby=order' still nothing happens :(

  9. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    please look at the last reply; it is heavily edited.

    i re-used the $cat variable within the code - this might be a reason ....

  10. mailinator007
    Member
    Posted 2 years ago #

    Thanks!!
    I got it working :))

    Now I'll try to build plugin from it, in order to enter category IDs from the dashboard, instead of editing PHP file directly :)

  11. aehageman
    Member
    Posted 2 years ago #

    Has a plugin been generated with these features?

Topic Closed

This topic has been closed to new replies.

About this Topic