• 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.

Viewing 10 replies - 1 through 10 (of 10 total)
  • 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.

    Thread Starter mailinator007

    (@mailinator007)

    Thank you very much!
    Although I’m not good in PHP, I’ll try to modify it ??

    Thread Starter mailinator007

    (@mailinator007)

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

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

    i have updated the post.

    Thread Starter mailinator007

    (@mailinator007)

    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 https://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.

    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:

    https://codex.www.ads-software.com/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

    Thread Starter mailinator007

    (@mailinator007)

    Yeah, I know. It is from ‘My category order’ plugin.
    Even after I delete plugin and remove ‘orderby=order’ still nothing happens ??

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

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

    Thread Starter mailinator007

    (@mailinator007)

    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 ??

    aehageman

    (@aehageman)

    Has a plugin been generated with these features?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘List posts within category menu?’ is closed to new replies.