Support » Fixing WordPress » Displaying most recent posts in 2 parts

  • I have a site design where the 3 newest posts are featured, and then farther down the page after other content I have an “Other Posts” section that I want to show the 7 next posts that chronologically follow the 3 featured posts.

    Basically newest post 1-3 are one part of the site, while posts 4-10 are somewhere else on the page. Is there any easy way to do this? Any help would be appreciated.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • esmi

    (@esmi)

    Forum Moderator

    I am guessing that you have two different div’s for the two sections. If so, something like this should work:

    $counter = 0;
    while (have_posts()) :
       ++$counter;
       if ($counter == 1) {
          // Start the first div
       } elseif ($counter > 3) {
          // End the first div
          // Start the second div
       }
       // Rest of the loop
    endwhile;
    // End the second div

    After thinking about this for a while, I believe this will work while the outline I posted earlier will not:

    $counter = 0;
    while (have_posts()) :
       ++$counter;
       if ($counter == 1) {
          // Start the first div
       } elseif ($counter == 4) {
          // End the first div
          // Start the second div
       }
       // Rest of the loop
    endwhile;
    if ($counter > 0) {
       // End the first/second div
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Displaying most recent posts in 2 parts’ is closed to new replies.