Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom taxonomy for a group of posts, and I also have a need to show these posts on a custom page template. I want to show one post at a time, with pagination, so that the user can click through them like a slide show.

My template correctly grabs the right category and display one (the first) post, but when I try to click through the pagination, it sends me to the archives for the next post. I want to click "next" and be taken to the next post within the same page template.

I've working with this solution, but I can't get it to work.

Here's my code, as it is...

<body <?php body_class(); ?>>
<div id="full-page">
    <div id="wrap">
        <div id="full-main-col">
            <a href="#" id="share" rel="prettySociable" title="Drag to Share"><img src="<?php echo get_template_directory_uri(); ?>/img/share.png" alt="" /></a>

            <?php if (have_posts()) :
                            while (have_posts()) :
                            the_post(); ?>

                                <div id="page-head">
                                    <?php the_title('<h1>', '</h1>');
                                    if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs(); ?>
                                </div>

                           <?php endwhile;
                        endif; ?>
            <?php include( TEMPLATEPATH . '/sidebar-right.php' ); ?>

            <?php
              query_posts( array( 'post_type' => 'fieldtrips', 'fieldtripcategory' => 'elementary-school-aquifer', 'order' => 'ASC', 'posts_per_page' => 1 ) );
              if ( have_posts() ) : while ( have_posts() ) : the_post();
            ?>

              <h3><?php the_title(); ?></h3>
              <?php the_content(); ?>

              <?php previous_post('&laquo; &laquo; %', '', 'yes'); ?> | <?php next_post('% &raquo; &raquo; ', '', 'yes'); ?>

            <?php endwhile; endif; wp_reset_query(); ?>

        </div>
    </div>
<?php
get_footer();
?>
share|improve this question
    
I suggest you read Querying Posts Without query_posts. Using query_posts is not a very good idea. –  Hamed Momeni Sep 22 '12 at 17:13
add comment

migrated from stackoverflow.com May 3 '12 at 15:08

This question came from our site for professional and enthusiast programmers.

2 Answers

query_posts = _your_doing_it_wrong

as soon as you throw in that nasty query_posts you are killing off all the global variables and your paging will not work.

change:

 query_posts( array( 'post_type' => 'fieldtrips', 'fieldtripcategory' => 'elementary-school-aquifer', 'order' => 'ASC', 'posts_per_page' => 1 ) );
              if ( have_posts() ) : while ( have_posts() ) : the_post();

to:

   $my_query = new WP_Query( array( 'post_type' => 'fieldtrips',
                                    'fieldtripcategory' => 'elementary-school-aquifer',
                                     'order' => 'ASC',
                                     'posts_per_page' => 1
                          ));
                  if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : $my_query->the_post();

Also remove the wp_reset_query.

share|improve this answer
add comment

previous_posts() and next_posts() are deprecated. Try these instead:

get_next_post()

get_next_posts_link()

get_previous_post()

get_previous_posts_link()

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.