2011-02-01 50 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>