2011-02-01 51 views
1

这是我想结合WordPress的next_post_link()和previous_post_link()使用的HTML。你可以看到URL和标题被HTML标签包装,甚至还有single_cat_title()。因为这个评估者复杂 HTML设置我不能轻易使用next_post_link()和previous_post_link()。WordPress的:我如何检索next_post_url()和next_post_title()?

那么我该如何实现以下目标?我觉得我缺少像next_post_url()和next_post_title()这样的标签。

<p class="prev-next clearfix"> 
     <a href="http//loremipsum.com" class='prev <?php single_cat_title(); ?>'> 
     <span class="header">Previous article</span> 
     <span class="title">Lorem ipsum dolores amet title</span> 
     </a> 
     <a href="http://foorbar.com" class='next <?php the_filmcom_category(); ?>'> 
     <span class="header">Next article</span> 
     <span class="title">Foo bar title</span> 
     </a> 
    </p> 

回答

2

我使用get_adjacent_post()检索next和prev文章解决了这个问题。然后使用get_permalink()和get_the_title()。

<?php $nextpost = get_adjacent_post(true,'',false); ?> 
    <?php $prevpost = get_adjacent_post(true,'',true); ?> 

    <p class="prev-next"> 
     <a href="<?php echo get_permalink($prevpost); ?>" class='prev <?php the_filmcom_category(); ?>'> 
     <span class="header">Previous article</span> 
     <span class="title"><?php echo get_the_title($prevpost); ?></span> 
     </a> 
     <a href="<?php echo get_permalink($nextpost); ?>" class='next <?php the_filmcom_category(); ?>'> 
     <span class="header">Next article</span> 
     <span class="title"><?php echo get_the_title($nextpost); ?></span> 
     </a> 
    </p>