Performance: The Loop and query
HIGH IMPACT
This affects how fast WordPress loads posts and content on a page, impacting the time to show main content.
<?php $args = array('posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC'); $query = new WP_Query($args); if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?> <?php the_excerpt(); ?> <?php endwhile; wp_reset_postdata(); endif; ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php the_content(); ?> <?php endwhile; endif; ?>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Default Loop with no limits | High (many posts) | Multiple reflows per post | High paint cost due to large content | [X] Bad |
| Custom WP_Query with limits and excerpts | Low (few posts) | Single reflow after loop | Low paint cost with smaller content | [OK] Good |