Lego2012
12/13/2016 - 3:50 PM

Query + Loop

Query + Loop

<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.

// WP_Query arguments
$args = array (
   'post_type'              => 'slide',
);

// The Query
$query = new WP_Query( $args );

// The Loop
if ( $query->have_posts() ) {
   echo '<div class="home-slides">';
   while ( $query->have_posts() ) {
      $query->the_post();
      // do something
      echo '<div class="home-slide">';
         // image
         $image = genesis_get_image( 'format=url&size=home-slide' );
         printf( '<div class="slide-image"><a href="%s" rel="bookmark"><img src="%s" alt="%s" /></a></div>', get_permalink(), $image, the_title_attribute( 'echo=0' ) );
         ?>

         <div class="home-slide-caption">
            <div class="home-slide-excerpt">
               <!-- title -->
               <h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>" class="slide-title"><?php the_title(); ?></a></h2>
               <!-- content -->
               <?php the_content(); ?>
            </div>
         </div>

      </div>
   <?php }
   echo '</div>';
} else {
   // no posts found
}

// Restore original Post Data
wp_reset_postdata();