我是php的新手,所以我想得到一些帮助。
我的客户希望下一个和上一个按钮在单页组合中循环。这是我正在使用的代码。
<?php
$prev_post = get_previous_post();
$next_post = get_next_post();
$prev_post_link = !empty($prev_post) ? get_permalink($prev_post->ID) : true;
$next_post_link = !empty($next_post) ? get_permalink($next_post->ID) : true;
if(!empty($prev_post) && empty($prev_post_thumb)) $prev_post_thumb = prev_next_post_format_icon($prev_post->ID);
if(!empty($next_post) && empty($next_post_thumb)) $next_post_thumb = prev_next_post_format_icon($next_post->ID);
?>
当我使用True时,对于Previous和amp; Next Links,它出现在第一个和最后一个投资组合中,但超链接显示为http://1而不是下一个投资组合。在此先感谢
这是我的HTML代码:
<div class="dfd-controls mobile-hide">
<?php if(!empty($prev_post_link)) : ?>
<a href="<?php echo esc_url($prev_post_link); ?>" class="page-inner-nav nav-prev">
<div class="dfd-controler prev">
<div style="margin-top:7px; color:#fff;">Previous</div>
<!-- <div class="thumb prev">
<?php echo $prev_post_thumb; ?>
</div> -->
</div>
<!--<div class="pagination-title">Previous Project</div> -->
</a>
<?php endif; ?>
<?php if(!empty($next_post_link)) : ?>
<a href="<?php echo esc_url($next_post_link); ?>" class="page-inner-nav nav-next">
<div class="dfd-controler next">
<div style="margin-top:7px; color:#fff;">Next</div>
<!-- <div class="thumb next">
<?php echo $next_post_thumb; ?>
</div>-->
</div>
<!--<div class="pagination-title">Next Project</div>-->
</a>
<?php endif; ?>
答案 0 :(得分:0)
将值从true更改为false。将变量设置为true会使empty
为假值see here。
现在&#39; next&#39;只会显示是否有下一篇文章
你的PHP应该是:
$prev_post = get_previous_post();
$next_post = get_next_post();
$prev_post_link = !empty($prev_post) ? get_permalink($prev_post->ID) : false;
$next_post_link = !empty($next_post) ? get_permalink($next_post->ID) : false;
if(!empty($prev_post) && empty($prev_post_thumb)) $prev_post_thumb = prev_next_post_format_icon($prev_post->ID);
if(!empty($next_post) && empty($next_post_thumb)) $next_post_thumb = prev_next_post_format_icon($next_post->ID);
更新:要发布帖子:
if( get_adjacent_post(false, '', true) ) {
previous_post_link('%link', '<div class="dfd-controler prev"><div style="margin-top:7px; color:#fff;">Previous</div></div>');
} else {
$first = new WP_Query('posts_per_page=1&order=DESC'); $first->the_post();
echo '<a href="' . get_permalink() . '"><div class="dfd-controler prev"><div style="margin-top:7px; color:#fff;">Previous</div></div></a>';
wp_reset_query();
};
if( get_adjacent_post(false, '', false) ) {
next_post_link('%link', '<div class="dfd-controler next"><div style="margin-top:7px; color:#fff;">Next</div></div>');
} else {
$last = new WP_Query('posts_per_page=1&order=ASC'); $last->the_post();
echo '<a href="' . get_permalink() . '"><div class="dfd-controler next"><div style="margin-top:7px; color:#fff;">Next</div></div>';
wp_reset_query();
};
答案 1 :(得分:0)
循环投资组合Wordpress中的下一个/上一个按钮
<div class='next_post_link_align'>
<?php next_post_link('<span class="previous_post_link">← %link </span> <span class="post_link_text">'.__('(previous entry)','avia_framework'))."</span>";?>
</div>
<div class='previous_post_link_align'>
<?php previous_post_link('<span class="next_post_link"><span class="post_link_text">'.__('(next entry)','avia_framework').'</span> %link →</span>'); ?>
</div>