Support » Themes and Templates » Best way to have two loops?

  • There doesn’t seem to be consunsus on how mest to have two passes of the loop. There are a couple of suggestions I have read.

    What I require, is to have the first 5 posts in full (up to the more), then the next 10 with just their titles.

    How is the best way to do this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • You actually only need one loop to do this. Just add a counter right after the loop starts and an if/else statement. If the counter is <=5, then the_content….else, the_excerpt.

    السلام على من اتبع الهدى
    اما بعد Ù?قد وردنا انكم قمت بالسب Ù?Ù‰ الاسلام والمسليمين
    ونحن سوÙ? نقاطع منتجاتكم ايها الاعداء اعداء الاسلام انالله سوÙ? ينصرنا عليكم ايها الحقيرون ابناع العاهرات حتى لو وصل الموضوع لاراقة الدماء امضاء

    hi saracen, i am also looking for the same code as u asked . can u post that code for the loop pls. the first 5 posts in full and next 5 just titles.

    Thread Starter saracen

    (@saracen)

    How about if I require the two sections to be in different parts of the page with different CSS applied?

    Then you should wrap them in different xhtml blocks, say <div>´and give them different classes <div class=”first5″>´ ´<div class=”therest”>´ and then figure out a way of placing the blocks with CSS.

    Admittedly tricky, because the blocks must come in the correct sequence in the document flow.

    Only if you do absolute positioning, can you place the two blocks whereverever you want. But then you as for trouble.

    You also could use rewind_posts and query_posts. I did this for the Musil theme.

    If you look at the home page for example, you’ll see four WordPress loops working (one for the featured post, one for the sidenotes, one for recent posts and one for the rest of the posts).

    Be aware, that you might have to save and restore some internal WordPress variables to get it all working correctly. Peek at my source for examples. 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Best way to have two loops?’ is closed to new replies.