在我为博客做的单一文章导航中,我期待获得上一个和下一个帖子ID来显示标题并获得固定链接。WordPress的单篇文章导航和get_adjacent_post
我试图get_adjacent_post()
和get_previous_post()/get_next_post()
,但有没有办法得到任何有关它的信息...(<?php print_r($prev) ?>
回报空白)
我只是有一个的index.php文件使用此代码:
if (have_posts()) while (have_posts()) : the_post();
$prev = get_adjacent_post(false, "", true);
$next = get_adjacent_post(false, "", false);
<ul>
<li id="prev">
<?php //if (!empty($prev)) : ?>
<a href="<?= get_permalink($prev->ID) ?>">
<div>
<time datetime="<?= get_the_date("Y-m-i", $prev->ID) ?>"><?= get_the_date("j F", $prev->ID) ?></time>
<span><i></i></span>
</div>
</a>
<?php //endif ?>
</li>
<li class="center"></li>
<li id="next">
<?php //if (!empty($next)) : ?>
<a href="<?= get_permalink($next->ID) ?>">
<div>
<time datetime="<?= get_the_date("Y-m-i", $next->ID) ?>"><?= get_the_date("j F", $next->ID) ?></time>
<span><i></i></span>
</div>
</a>
<?php //endif ?>
</li>
</ul>
你的代码有什么错误? – John
我的'print_r($ prev)'只是没有返回任何内容... – flks
接下来呢?确定你没有查看最新的帖子吧? –