I am new to wordpress development, just trying to convert my HTML into a WordPress theme, I started with Chris Coyer’s blank theme.
<div class="navigation">
<div class="next-posts">
<?php next_posts_link('« Older Entries') ?>
</div>
<div class="prev-posts">
<?php previous_posts_link('Newer Entries »') ?>
</div>
</div>
How can I output the div only if there is a next_posts_link()
. I need this as I will be using <ul>
for my pagination. If I don’t do that, I will get an empty bullet
You can use get_previous_posts_link
and get_next_posts_link
to determine if they exists like this:
$prev_link = get_previous_posts_link(__('« Older Entries'));
$next_link = get_next_posts_link(__('Newer Entries »'));
// as suggested in comments
if ($prev_link || $next_link) {
echo '<ul class="navigation">';
if ($prev_link){
echo '<li>'.$prev_link .'</li>';
}
if ($next_link){
echo '<li>'.$next_link .'</li>';
}
echo '</ul>';
}
Hope This Helps