Skip to content

Instantly share code, notes, and snippets.

@twentyfortysix
Last active March 12, 2016 17:39
Show Gist options
  • Save twentyfortysix/4414482 to your computer and use it in GitHub Desktop.
Save twentyfortysix/4414482 to your computer and use it in GitHub Desktop.
WP - custom query
$out = '';
$page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'page',
'posts_per_page' => '100',
'paged' => $page
);
// The Query
$the_query = new WP_Query( $args );
if ($the_query->have_posts()) :
// The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
$postClass = get_post_class(array('my-class'));
$postClassString = '';
foreach($postClass as $class){
$postClassString .= $class . ' ';
}
$out .= '<div class="'.$postClassString.'">';
$thumb = get_the_post_thumbnail($the_query->post->ID, 'thumbnail');
$thmb_html = '';
if(!empty($thumb)){
$thmb_html .= '<div class="featured_img">';
$thmb_html .= '<a href="'.get_permalink().'" title="'.get_the_title().'">';
$thmb_html .= $thumb;
$thmb_html .= '</a>';
$thmb_html .= '</div>';
}
$out .= $thmb_html .'
<h2>
'.get_the_title().'
</h2>
<div class="entry">'.
apply_filters('the_content', get_the_content()).'
</div>';
$out .= '</div>';
endwhile;
endif;
// Restore original Query & Post Data
wp_reset_postdata();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment