Rob
Rob

Reputation: 1495

Display next posts when non previous

I have a wordpress theme displaying the Next / Previous post but having some trouble when you're viewing the first post.

Obviously on the first post there are no other posts previous, however I would like to display the next post 2 posts

My current code looks like:

<?php next_post('%','', TRUE, '1'); ?>
<?php previous_post('%','', TRUE, '1'); ?>

Upvotes: 4

Views: 213

Answers (2)

Tiago Gouv&#234;a
Tiago Gouv&#234;a

Reputation: 16740

Let'me try. You can check the position on the loop, to check if it is on beginning or in 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 get it better.

Upvotes: 1

Junius L
Junius L

Reputation: 16122

I usually get the current page and then apply a class to that 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 pagination script on github php paginator

Upvotes: 2

Related Questions