Created
January 17, 2014 23:30
-
-
Save kisabelle/8483624 to your computer and use it in GitHub Desktop.
Pagination with Custom Post Types in WordPress
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
<?php | |
//setup new query | |
$query = new WP_query( | |
array( | |
'posts_per_page' => 10, // ?? | |
'post_type' => 'custom-post-type', // custom post type | |
'paged' => get_query_var('paged'), | |
'meta_key' => 'wpcf-meta-key', | |
'orderby' => 'meta_value title', | |
'order' => ASC, | |
'meta_value' => $meta_value, | |
'location' => $currentLocation, // custom taxonomy | |
'vendor-type' => $currentVendorType, // custom taxonomy | |
) | |
); | |
?> | |
<?php if ($query->have_posts()): ?> | |
<?php while ($query->have_posts()) : $query->the_post(); ?> | |
<!-- display posts --> | |
<?php endwhile; ?> | |
<?php else: ?> | |
<!-- fallback --> | |
<?php endif; ?> | |
<?php | |
$total_pages = $query->max_num_pages; | |
$args = array( | |
'base' => preg_replace('/\?.*/', '/', get_pagenum_link(1)) . '%_%', | |
'format' => 'page/%#%', | |
'current' => max( 1, get_query_var('paged') ), | |
'total' => $total_pages, | |
'show_all' => False, | |
'end_size' => 1, | |
'mid_size' => 2, | |
'prev_next' => False, | |
'prev_text' => __('« Previous'), | |
'next_text' => __('Next »'), | |
'type' => 'plain', | |
'add_args' => array( | |
'vendor-type' => get_query_var('vendor-type'), | |
'vendor-location' => get_query_var('vendor-location') | |
), | |
'add_fragment' => '' | |
); | |
?> | |
<?php if($total_pages > 1): ?> | |
<nav class="vendor-nav group"> | |
<h1 class="hidden">Blog Post Navigation</h1> | |
<span class="older"> | |
<?php next_posts_link('<div class="circle"><span class="arrow-e"></span></div>', $blush_vendor_query->max_num_pages) ?> | |
</span> | |
<span class="paginate-links"> | |
<?php echo paginate_links( $args ); ?> | |
</span> | |
<span class="newer"> | |
<?php previous_posts_link('<div class="circle"><span class="arrow-w"></span></div>', $blush_vendor_query->max_num_pages) ?> | |
</span> | |
</nav> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment