So I’ve been trying to create pagination for my custom post type which is on my one page theme. Here is the theme http://wp.themechills.com/eternity/. After numerous hours of Google research, etc, I have come to no solution.
Within the theme I generate custom post types for the Photos section. The problem is I only want the 8 posts to show and then paginate while still on the front page – essentially an ajax call + pagination.
I created a test version here http://wp.themechills.com/sandbox/ just to test without all the clutter.
As you can see, the pagination links to a 404.
Here is my code block for reference. I would really appreciate it if someone can lend me their brain…thoughts?
<?php $type = 'photo'; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args=array( 'post_type' => $type, 'post_status' => 'publish', 'paged' => $paged, 'posts_per_page' => 8, 'caller_get_posts'=> 1 ); $temp = $wp_query; // assign original query to temp variable for later use $wp_query = null; $wp_query = new WP_Query(); $wp_query->query($args); ?> <?php if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <div class="entry"> <h2 class="title"><?php the_title(); ?></h2> </div> <?php endwhile; ?> <div class="navigation"> <div class="alignleft"><?php next_posts_link('« Older Entries') ?></div> <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div> </div> <?php else : ?> <h2>Not Found</h2> <p>Sorry, but you are looking for something that isn't here.</p> <?php endif; ?>
ThemeChills saidIn admin dashboard: https://www.dropbox.com/s/su0hcj16jmqfnwg/scr-00081-002%20%281%29.png
Smartik saidWhat do you mean?
Go to “Permalink Settings” and click “Save Changes” button.
Thanks guys, I know where saving the permalinks structure is and these have been saved, though this does not resolve my issue.
First of all (but shouldn’t affect things in a 404 way), your $paged variable is wrong. This is how it should look:
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : ( get_query_var( 'page' ) ? get_query_var( 'page' ) : 1 );
First of all (but shouldn’t affect things in a 404 way), your $paged variable is wrong. This is how it should look:$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : ( get_query_var( 'page' ) ? get_query_var( 'page' ) : 1 );
You have just solved a problem iv been having all morning – Thank you!
Issue still remains. Might need to consider alternatives…
Your code has several problems. Here is the corrected version: http://pastebin.com/T55a8gMX
caller_get_posts– is deprecated and replaced by
- You should never alter the
$wp_queryvariable, use your own var instead. I’ve replaced it for you with
$wp_query->query($args);is useless. The args should be added directly to WP_Query class.
new WP_Query( $args );
- Are you sure the ‘photo’ post type exists? Check it with this:
var_dump( get_post_types( '', 'names' ); )
- Is your post type: public, has archive and is publicly queryable? When registering a new post type, these are some of the required parameters:
$post_type = 'photo' // Set up the arguments $args = array( // ... 'public' => true, 'has_archive' => true, 'publicly_queryable' => true, 'query_var' => true, 'rewrite' => array( 'slug' => $post_type, // or something else ), // ... ); // Register post type register_post_type( $post_type, $args );