• Hello, i have this code: https://pastebin.com/tF2c63Mb

    Now posts show only on sub-categories. I need to show posts even when category doesn’t have sub-categories.

    I need like this:
    Category – > Show posts

    Now its like this:
    Category – > Posts don’t show
    Category -> Sub-category – > Posts

    I purpose that the code needs to check if category does not have subcategory ant then loop posts.

    Maybe anybody knows hot so solve?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m not sure I understand. Do you want only posts of the current category if there are no child categories or posts of the current category regardless if there are child categories or not?

    If the former, only run the loop if( 0 == count($categories)). Or something like that, I’m not sure what get_categories() actually returns if there are no children. Whatever that is, check for it as a condition for running the loop.

    If the latter, merge the current category as an array with the $categories array before running the loop: $categories = array_merge((array) $cat, $categories);

Viewing 1 replies (of 1 total)
  • The topic ‘How to loop posts even if category does nt have sub-categories’ is closed to new replies.