2014-03-18 63 views
0

在我为博客做的单一文章导航中,我期待获得上一个和下一个帖子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> 
+0

你的代码有什么错误? – John

+0

我的'print_r($ prev)'只是没有返回任何内容... – flks

+0

接下来呢?确定你没有查看最新的帖子吧? –

回答

0

Woooookay。由于我不知道为什么,我停用了“类别”分类法,所以它打破了这些功能... Mea culpa。

0

看起来像是在和while之间缺少:陈述

if (have_posts()) : while (have_posts()) : the_post();

+1

hm我不这么认为,“循环”在“if”中没有':'。 (以及它始终与我的所有模板一起使用) – flks