• astereo

    (@astereo)


    I’ve been modding up WordPress like crazy to get my site finished. My layout looks like this:

    https://www.devlounge.net/wordpress/test

    What i want to do is, in the four blocks under “Lastest Articles & Interviews”, be able to pull the most recent from my articles and interviews category, but have them seperated into one post excerpt per column.

    (Example: Call recent posts (in this case, 4, one for each column, and spread them across all four divs. So maybe, the first block would have a title, and a very small excerpt under it. In the next block, it would continue showing the next most recent from category “x”)

    I don’t know if it’s possible to do this, but if it is, can someone please explain.

Viewing 8 replies - 16 through 23 (of 23 total)
  • moshu

    (@moshu)

    Hey, Rachel, your tutorial doesn’t say anything about this situation when you have category A and B, both have 2 posts and you want to display them, like
    A1 B1 A2 B2

    cre8d

    (@cre8d)

    Ahh – I read the top question (which would work perfectly with my tutorial) but didn’t notice the extra detail mentioning the alternating.

    Off the top of my head, couldn’t you just pull out the 2 most recent posts from each category, storing them in variables, then displaying them in the correct order afterwards?

    Kafkaesqui

    (@kafkaesqui)

    I was asked to add something to the discussion, and this is the best I can work out on short notice…

    First, set up different query classes for the (2) posts in each category:

    <?php
    $article = new WP_Query('category_name=Articles&showposts=2');
    $interview = new WP_Query('category_name=Interviews&showposts=2');
    ?>

    Then in each column, just add a call to the_posts() through your new classes, alternating each time, before using any regular template tags:

    <?php $article->the_post(); ?>
    ~ article 1 here ~
    <?php $interview->the_post(); ?>
    ~ interview 1 here ~
    <?php $article->the_post(); ?>
    ~ article 2 here ~
    <?php $interview->the_post(); ?>
    ~ interview 2 here ~

    the_post() will (or should) handle the step through to the following post in each category automatically. No true loop functionality here, but this should work for you.

    Thread Starter astereo

    (@astereo)

    Great, I’ll try working with it in the morning and let you know how it goes.

    davidchait

    (@davidchait)

    Kafka beat me to it, but a slightly different solution.

    Do your two loops, but put the output into arrays. this is pseudocode, obviously!

    $outstuff = array();

    $i = 0;
    loop1 (articles)… {
    $outstuff[$i] .= content for this post…
    $i += 2;
    }
    $i = 1;
    loop2 (interviews)… {
    $outstuff[$i] .= content for this post…
    $i += 2;
    }

    for ($i=0; $i<4; $i++)
    echo $outstuff[$i];

    … etc.

    In many cases, easier to pre-cache the output stuff.

    Note, if the thing becomes a real bear, you could use PHP’s output buffering system to catch the WP functions that echo directly, and capture each post’s output along the way. Then order/reorder as you see fit.

    -d

    Kafkaesqui

    (@kafkaesqui)

    David, when I read through the thread my original starting thought on how to accomplish this wasn’t far off from your solution, and if I was doing the actual work I’d probably go with it considering the greater flexibility it allows. But then the little idea above came to mind, and I figured: Hey why not, it’s simple. ;)

    Thread Starter astereo

    (@astereo)

    David, I not much of a coder, so could you explain how I’d put it all together?

    Thanks, sorry to keep bugging you guys!

    gMk

    (@gmk)

    Check out the customizable post listings plugin – makes for easy manipulation of various categories and posts

    https://www.coffee2code.com/archives/2004/08/27/plugin-customizable-post-listings/

Viewing 8 replies - 16 through 23 (of 23 total)
  • The topic ‘Advanced Layout : Is this possible?’ is closed to new replies.