I'm currently working on a WP theme using version 3.1.1 and have a small issue with category.php pagination. For design/aesthetic reasons, I wish to show the 'previous entries' and 'newer entries' at all times including first and last pages. I realize that 'newer entries' on the first paginated page would lead to nowhere, but need it to be displayed. For the life of me I can't solve this problem and would appreciate any help.
Hi use get_previous_post() and get_next_post(), instead of previous_post_link() and next_post_link(). The latter to do not return anything, making it hard to determine if they printed anything (e.g. are on first or last post). You can then check there is a next or previous post with empty(), and create a conditional statement for echoing out a placeholder when there is no next/previous post.
There does not seem to be a return version of next and previous_post_link() functions.
Almost what I'm looking for, magnuseide, but not quite. Thank you for responding.
I tried the above code and it lists the next and previous posts, rather than the next and previous pages. Maybe I should rephrase the question.
I have a category.php page that lists all posts filed under a specific category. This page lists the 9 most recent posts and then kicks in the pagination for page 2, displaying posts 10-18, etc. It is on this category.php page that I wish to display 'previous entries' and 'newer entries' at all times, especially the first and last pages.
Ahh, i see, then my solution won't work for you. This should do the trick:
<?php global $wp_query; //get current page $page = get_query_var('paged'); //gets total pages $total_pages = absint( $wp_query->max_num_pages );
//if it's the first page, echo placeholder if ($page == '0') { echo '<span>Previous placeholder</span>'; //and set variable to 1 to make it work in next function $page = 1; } //or echo link to previous page else { echo '<a href="'.get_pagenum_link($page -1).'">Previous page</a>'; }
//if it's current page is the same as total number of pages, echo placeholder if ($page == $total_pages) { echo '<span>Next placeholder</span>'; } // else echo link to next page else { echo '<a href="'.get_pagenum_link($page + 1).'">Next page</a>'; } ?>
Worked perfectly! Thank you very much, magnuseide. You clearly know your stuff. I couldn't find much documentation on this and resorted to this forum as a last-ditch effort. This is my first time in here and I'm thoroughly impressed with the outcome. Again, thank you.
Thanks Shawn Just fyi I did some edits to my post, added some comments and made some minor adjustments.
This is actually my first time on these forums myself. Been a long time reader of css-tricks though. I wrote a function for some advanced page navigation in wordpress for a theme a few months ago and learned a lot about how WP handles pagination. It's not well documented, and most of it I learned from reading the source files of the WP-PageNavi plugin.
Thanks for the tweaks and for commenting the code. I used the WP-PageNavi plugin on an older blog for a good part of a year. I never thought about peaking at the code and making use of it. I really appreciate your help.
Hi guys! After a week trying everything, trying lots of tutorials and advices, read meny forum and support I can´t put the wp page navi to work. When I click the numbers I got "Not Found". Can you help me? Thanks in advance.
Here is my code.
<?php query_posts ('showposts=5&cat=3'); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
I saw your code above and thought maybe it could be used to solve my problem. I tried it and it does show pagination but unfortunately, I get the no posts found search page when it should actually show a page. I am trying to get pagination for posts but just can't figure out how to do it. If you have time, please refer to this post that I made for the information
Thanks,
Shawn
use get_previous_post() and get_next_post(), instead of previous_post_link() and next_post_link(). The latter to do not return anything, making it hard to determine if they printed anything (e.g. are on first or last post). You can then check there is a next or previous post with empty(), and create a conditional statement for echoing out a placeholder when there is no next/previous post.
There does not seem to be a return version of next and previous_post_link() functions.
I tried the above code and it lists the next and previous posts, rather than the next and previous pages. Maybe I should rephrase the question.
I have a category.php page that lists all posts filed under a specific category. This page lists the 9 most recent posts and then kicks in the pagination for page 2, displaying posts 10-18, etc. It is on this category.php page that I wish to display 'previous entries' and 'newer entries' at all times, especially the first and last pages.
This should do the trick:
Just fyi I did some edits to my post, added some comments and made some minor adjustments.
This is actually my first time on these forums myself. Been a long time reader of css-tricks though. I wrote a function for some advanced page navigation in wordpress for a theme a few months ago and learned a lot about how WP handles pagination. It's not well documented, and most of it I learned from reading the source files of the WP-PageNavi plugin.
After a week trying everything, trying lots of tutorials and advices, read meny forum and support I can´t put the wp page navi to work. When I click the numbers I got "Not Found". Can you help me? Thanks in advance.
Here is my code.
<?php query_posts ('showposts=5&cat=3'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
<?php echo strtoupper(get_the_time('F')); ?>
<?php the_time('d'); ?>
<?php the_title(); ?>
<?php the_content('Read More +');?>
<?php endwhile; else: ?>
<?php endif; ?>
<?php wp_pagenavi(); ?>
@magnuseide
I saw your code above and thought maybe it could be used to solve my problem. I tried it and it does show pagination but unfortunately, I get the no posts found search page when it should actually show a page. I am trying to get pagination for posts but just can't figure out how to do it. If you have time, please refer to this post that I made for the information
http://wordpress.stackexchange.com/questions/67836/how-to-paginate-get-categories
can you help?