After pretty much getting everything working with query_posts
, I noticed my pagination wasn't running. I was told pre_get_posts
should be the solution.
My problems:
- I don't know how to pass all my criteria
(query_posts(array('post_type' => 'trips', 'types' => $types, 'paged' => $paged,)
in topre_get_posts
I can't get it working on (just) the template I want, which is used on a page (
is_page
doesn't work)Any help would be appreciated.
This is what's inside functions.php
function bwpm_pre_get_posts($query){
if(!$query->get('posts_page_page'))
$query->set('posts_per_page',1);
}
add_action('pre_get_posts','bwpm_pre_get_posts');
This is what's in the template that is used on the page.
<?php
/*
Template Name: Generic Trips Template
*/
?>
<?php get_header(); ?>
<?php get_template_part( "beforeloop", "page" ) ?>
<?php $types = $post->post_name; ?>
<?php if (have_posts()) : ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array(
'post_type' => 'trips',
'types' => $types,
'paged' => $paged,
) );
?>
<?php while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" class="post"></article>
<?php endwhile; ?>
<div style="text-align:center;">
<?php posts_nav_link(' · ', 'previous page', 'next page'); ?>
</div>
<?php endif; wp_reset_query(); ?>
<?php get_template_part( "afterloop", "page" ) ?>
<?php get_footer(); ?>
Update: 11/06/2012 After updating the code to @chipbennet example, the problem still isn't solved as I don't get properly working pagination. The previous link will never appear, and the next link will show the same content on every page. Full page code can be found on http://pastebin.com/NiuSEWia.
is_page
, but that ain't working. I've also tried to get more criteria in to thepre_get_posts
, but can't find a good example and that ain't working either. If anyone has a good example... .query_posts
, but didn't get pagination working. Now I'm trying to basically get everything working the way it was when I WAS usingquery_posts
, and also get pagination working. Unfortunately, I don't know how to pass all my criteria in topre_get_posts
, nor do I seem to manage to get it working on the template I want it.