8 Responses

  1. Kostas Nicolacopoulos
    Kostas Nicolacopoulos Published |

    Thanks for the reminder Justin! I am guilty of using the $i iterator out of habit way too often. I need to make an effort to use current_post instead.

  2. Jez Thompson
    Jez Thompson Published |

    Very interesting article, thanks Justin.

    What about dividing a set amount of posts, can this method be used to achieve that as well?

    For example you have 30 posts and want to divide them into 3 columns of 10 posts each, could this work for that as well?

  3. John Blackbourn
    John Blackbourn Published |

    A similar approach is to use template parts to avoid messy logic in the main template.

    For example:

    while ( have_posts() ) {
    get_template_part( 'loop', $wp_query->current_post );

    This basic example results in you being able to use loop-0.php for the first post, and loop.php for all others.

    1. Luke Burford
      Luke Burford Published |

      This is indeed a much cleaner way of doing this for a post with a specific place in the loop, going straight in my snippets list 🙂

      Definitely overused the more common idiom for this many times, forgetting how much WP_Query gives us out the box.

  4. 龙笑天
    龙笑天 Published |

    don’t need “wp_reset_postdata()”?

Comments are closed.