Show the following messages when there wasn’t

I have a Wordpress theme displaying a Next / Previous message, but with some problems when you view the first message.

Obviously, in the first post there are no other posts from the previous one, however I would like to display the following post 2 posts

My current code is as follows:

<?php next_post('%','', TRUE, '1'); ?>
<?php previous_post('%','', TRUE, '1'); ?>
+4
source share
2 answers

Usually I get the current page and then apply the class to this page, I don’t know if you can do this in wordpress.

// find the current page
$current_page = basename($_SERVER['SCRIPT_FILENAME']);
$class = '';
 if($current_page === 'index.php'){
   $class = ' hide'; //hide the previous link if the current page is index.php or the first page.
 }
<ol>
   <li class="<?php echo $class; ?>"><a href="somepage.php">prev</a></li>
   <li><a href="somepage.php">1</a></li>
   <li><a href="somepage.php">2</a></li>
 </ol>

also check this php paginationscript on github php paginator

+2
source

Let's try. You can check the position in the loop, check whether it is at the beginning or at the end.

$firstPost=( $wp_query->current_post == 0 && !is_paged() );
$lastPost=( $wp_query->current_post == 0 && $wp_query->current_pos $wp->query->post_count-1 );

You can change something to improve it.

+1
source

All Articles