I am building a wordpress theme I want to have the next and previous DIV only appear IF their is a next and previous button available.
If there is 10 posts and the display limit is 10 posts I don’t want an empty div. However when there are 20 posts and the display limit is 10 I want the next and previous buttons to show in there own div.
I got this far and realized that posts_nav_link() doesn’t return null.
function next_previous_div(){
print '<!-- ';
$output = posts_nav_link();
print " -->\n";
if ($output != null)
{
echo '<div class="float post" style="text-align:center">';
echo posts_nav_link();
echo '</div><!-- end post-->';
};
};
There are a few different ways you could test if you’ll have a previous/next link:
Test $wp_query->max_num_pages
Get a global reference to the $wp_query object and see if it’s greater than 1. If yes, you’ve got paging links:
Capture the output of posts_nav_link()
This function echos by default, which is why your null test isn’t working. You need to capture the echoed output and then test: