Created
July 27, 2012 15:56
-
-
Save smeyer/3188828 to your computer and use it in GitHub Desktop.
Display posts with pagination and WP_Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** Function for displaying post content from a custom type for feed page with pagination */ | |
function env_display_posts_from_type($the_type, $the_num, $orderby, $the_order, $meta_url, $detailpg = 'false', $thumbsize ='', $inc_date = 'false', $status = 'publish') | |
{ | |
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; | |
$args = array( | |
'post_type' => $the_type, | |
'posts_per_page' => $the_num, | |
'orderby' => $orderby, | |
'order' => $the_order, | |
'paged' => $paged, | |
'post_status' => $status, | |
'ignore_sticky_posts' => 1 | |
); | |
global $wp_query; | |
$wp_query = new WP_Query( $args ); | |
if( $wp_query->have_posts() ): while ( $wp_query->have_posts() ) : $wp_query->the_post(); | |
global $post; | |
if ($meta_url != '') $post_url = get_post_meta($post->ID, $meta_url, true); | |
?> | |
<div class="article clear"> | |
<?php if (has_post_thumbnail()) { if ($detailpg == 'true') { echo '<a href="'; the_permalink(); echo '">'; } else if ($post_url) { ?><a href="http://<?php echo $post_url; ?>" rel="bookmark" target="_blank"><?php } ?><div class="thumb_image noborder"><?php the_post_thumbnail($thumbsize); ?></div><?php if (($detailpg == 'true') || $post_url) { echo '</a>'; } } ?> | |
<div class="entry-content <?php if (!has_post_thumbnail()) { echo 'no-thumb'; }?>"> | |
<h3><?php if ($post_url) { ?><a href="http://<?php echo $post_url; ?>" rel="bookmark" target="_blank"><?php } else if ($detailpg == 'true') { echo '<a href="'; the_permalink(); echo '">'; } the_title(); if ($inc_date == 'true') { echo ' - '; the_time('F d, Y'); } if ($post_url || $detailpg == 'true') { ?></a><?php } ?></h3> | |
<?php the_content(); ?> | |
</div> | |
</div> | |
<?php endwhile; else: ?> <br /><h2><?php _e('Sorry, no posts matched your criteria.'); ?></h2> <?php endif; ?> | |
<?php if (function_exists('wp_pagenavi') ) { ?> | |
<?php wp_pagenavi(); ?> | |
<?php } else { ?> | |
<div id="nav-below"> | |
<p class="screen-reader-text"><?php _e( 'Post navigation', 'env' ); ?></p> | |
<div class="nav-previous"><?php next_posts_link( __( '// More posts', 'env' ) ); ?></div> | |
<div class="nav-next"><?php previous_posts_link( __( '// Previous posts', 'env' ) ); ?></div> | |
</div> | |
<?php } | |
wp_reset_query(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment