WordPress Loop Help

Discussion in 'Web Design and Development' started by Melrose, May 25, 2009.

  1. Melrose Suspended

    Melrose

    Joined:
    Dec 12, 2007
    #1
    Generally, I love to try and figure things out for myself.

    This one has been trouble and a couple hours and several articles later I still can't seem to get my head around the solution.

    Problem
    I am coding up a WordPress theme - usually, I could do it fine. This design calls for the top story to be singled out and styled differently, and then the next four posts pulled out and treated regularly offset by 1, effectively).

    I have the partial solution already..

    Main story:
    Code:
    <?php
         $postslist = get_posts('numberposts=1&order=DESC&offset=0');
         foreach ($postslist as $post) : 
            setup_postdata($post);
         ?> 
    And for the next four posts:
    Code:
    <?php
         $postslist = get_posts('numberposts=4&order=DESC&offset=1');
         foreach ($postslist as $post) : 
            setup_postdata($post);
         ?> 
    However, this isn't inside the regular Loop, and it gives me the same page for every page except the single (obviously, because the post treatment is hard-coded). When I try to put this inside the The Loop and still make it work I get a blank page.

    In effect, I just need to have the above functionality inside the WordPress Loop so I can still have regular blog interaction. I know it's got to be a simple answer, but I can't seem to get it working (probably my head cold holds me back some also)

    Thanks! :)
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    A thought; use an iterator. Then when you enter the loop you can check if it's equal to zero, which would be the first post, and you can handle as needed. That may be an oversimplification. I haven't messed with WordPress layouts much.
     
  3. Melrose thread starter Suspended

    Melrose

    Joined:
    Dec 12, 2007
    #3
    That's what I thought - and while I must admit I get confused with While loops, (For loops seem to make more sense) it didn't work.

    The WP Loop is built in PHP, but works subtly different...

    I could Break the loop at the end of the first iteration, though. I hadn't thought of that.

    EDIT: Apparently, this doesn't work because of the WP Loop. Both
    Code:
    break 1; // or break;
    and
    Code:
    return;
    do not exit the Loop.

    Thanks :)
     
  4. Melrose thread starter Suspended

    Melrose

    Joined:
    Dec 12, 2007
    #4
    As usual, I figured it out myself digging around..

    Code:
    is_home();
     

Share This Page