7 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.

    Reply
  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?

    Reply
  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() ) {
    
    the_post();
    
    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.

    Reply
  4. 龙笑天
    龙笑天 Published |

    don’t need “wp_reset_postdata()”?

    Reply

Leave a Reply

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution.

Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.

css.php