我有一个显示下一篇/上一篇文章的wordpress主题,但在你查看第一篇文章时遇到了一些麻烦。
显然在第一个帖子上没有其他帖子,但是我想显示下一个帖子2个帖子
我当前的代码如下所示:
<?php next_post('%','', TRUE, '1'); ?>
<?php previous_post('%','', TRUE, '1'); ?>
发布于 2015-08-03 19:54:30
我通常获取当前页面,然后对该页面应用一个类,我不知道您是否可以在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>
还可以在github php paginator上检查这个php pagination
脚本
发布于 2015-08-08 01:43:59
让我试试。你可以检查循环的位置,检查它是在开始还是在结束。
$firstPost=( $wp_query->current_post == 0 && !is_paged() );
$lastPost=( $wp_query->current_post == 0 && $wp_query->current_pos $wp->query->post_count-1 );
你可以改变一些东西,让它变得更好。
https://stackoverflow.com/questions/31663150
复制相似问题