Forums

Show all posts belonging to child categories of the current category (3 posts)

  1. Pete
    Member
    Posted 1 year ago #

    I''ve looked everywhere but I can't find this...

    Show/display/list all the posts belonging to ONLY the child categories of the CURRENT category of the single post that is currently showing. So in effect the code is only useful when single.php is being called.

    Thanks heaps
    Pete

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    takes a few steps:

    first step: get the categories of the post - get_the_category()
    http://codex.wordpress.org/Function_Reference/get_the_category

    second step: get the child(ren) of each of these categories - get_categories()
    http://codex.wordpress.org/Function_Reference/get_categories

    collect all these cat child ids in an array, remove doubles, sort ascendent, turn into string;

    third step: the loop - query_posts()
    http://codex.wordpress.org/Function_Reference/query_posts

    http://wordpress.pastebin.com/jwThuY5R

  3. Pete
    Member
    Posted 1 year ago #

    Thanks so much... appreciated but it seems only to fetch one post and displays it twice rather than all the posts I have in the sub/child category?

    I found this which does it nicely but it also displays the current post (that is the post from the from the parent category), which I don't want.

Topic Closed

This topic has been closed to new replies.

About this Topic