• I want to create one or more category templates (category-x.php) that display nothing but always the most recent post from it´s one or more subcategories.

    Something that look likle this for example: http://www.wp-themes.der-prinz.com/branfordmagazine/a-three-column-page.

    Imagine this page (it´s a page template in this case but never mind) is a category template and the 3 columns show the 3 subcategories of this parent category.

    This category template of course should detect the subcategories automatically and dislay them with one article each.

    Something like:”if it is a category that has subcategories display the most recent article of each subategory that has at least one article”

    Doesn´t sound too difficult I thought but I simply can´t get it working. Can someone provide a code snipped?

    Thanks in advance
    Michael

Viewing 6 replies - 1 through 6 (of 6 total)
  • This code will display the title of your sub(child) pages. I hope this helps.

    <?php
    $mypages = get_pages(‘child_of=’.$post->ID.’&sort_column=post_date&sort_order=ASC’);

    foreach($mypages as $page)
    {

    ?>
    <?php echo get_the_title($page->ID) ; ?>

    <?php
    }
    ?>

    i would try it so:

    $cat = get_query_var('cat');
    $sub_cats = get_categories('parent='.$cat);
      if( $sub_cats ) :
        foreach( $sub_cats as $sub_cat ) :
        /*get the lates post of this subcat*/
        endforeach;
      endif;
    Thread Starter michael.oeser

    (@michaeloeser-1)

    @alchymyth: Seems to be the right way.

    Where you say /*get the lates post of this subcat*/ I need to run a WP query but I´m still not sure what to do there exactly.

    in a category archive, how to show one post per sub category, no duplicates, in three columns:

    a bit more elaborated:

    http://pastebin.com/MJWybtCv

    Thread Starter michael.oeser

    (@michaeloeser-1)

    That´s fantastic man. Seems to work great. I will now edit it a little but I can manage that on my own. Thanks very much indeed.

    you are welcome 😉

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Show Post from Subcategories on a Category Page’ is closed to new replies.