Thord Daniel Hedengren - Smashing WordPress_ Beyond the Blog-Wiley (2014)

(avery) #1

CHAPTER 3 • The Loop 59


<?php
// Featured loop ends
endwhile;
// Resetting
wp_reset_postdata();
?>



This is very similar to the featured post example from the previous subsection. There are a few
things that differ, though. First of all, you display three posts rather than just one, which in turn
means that you have to store these three post IDs in an array in $do_not_duplicate[].
You’ll ask for them in three subsequent queries.


The rest of the code here is just a simple output of post titles and such. Also, the HTML
markup is simple with some IDs and classes so that you can easily target the various parts
of the code using style sheets.


Moving on, take a look at the next loop:



Latest from Apples



    // Loop arguments
    $args = array(
    'category_name' => 'apples',
    'showposts' => 10
    );
    // Our query and loop
    $apple_query = new WP_Query( $args );
    while ( $apple_query->have_posts() ) : $apple_query->the_post();
    // Let's not output any featured posts
    if ( in_array( $post->ID, $do_not_duplicate ) ) continue;
    update_post_caches( $posts );
    ?>


  • title="">





  • // Loop ends
    endwhile;
    // Resetting
    wp_reset_postdata();
    ?>

Free download pdf