admin管理员组文章数量:1130349
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
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
3 Answers
Reset to default 20You 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
I wrote this up a while ago, but should still be valid:
http://www.ericmmartin/conditional-pagepost-navigation-links-in-wordpress-redux/
You can add the following function to your functions.php file:
/**
* If more than one page exists, return TRUE.
*/
function show_posts_nav() {
global $wp_query;
return ($wp_query->max_num_pages > 1);
}
The update your code to:
<?php if (show_posts_nav()) : ?>
<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>
<?php endif; ?>
the best solution is checking $wp_query->max_num_pages, but you also can use:
<?php
if(paginate_links()) {
...
}
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
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
3 Answers
Reset to default 20You 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
I wrote this up a while ago, but should still be valid:
http://www.ericmmartin/conditional-pagepost-navigation-links-in-wordpress-redux/
You can add the following function to your functions.php file:
/**
* If more than one page exists, return TRUE.
*/
function show_posts_nav() {
global $wp_query;
return ($wp_query->max_num_pages > 1);
}
The update your code to:
<?php if (show_posts_nav()) : ?>
<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>
<?php endif; ?>
the best solution is checking $wp_query->max_num_pages, but you also can use:
<?php
if(paginate_links()) {
...
}
本文标签: paginationHow to determine if theres a next page
版权声明:本文标题:pagination - How to determine if theres a next page 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749194858a2330803.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论