2014-03-28 52 views
0

WordPress的自定義帖子類型:是否可以將導航功能集成到元素的<a> -tag中?WP:上一篇/下一篇文章作爲鏈接<a> -tag

讓我們說在single-customposttype.php文件我有一個彩色框。當您點擊它時,必須出現自定義帖子類型的下一篇文章。

我嘗試這樣做,但它不工作:

<a href="<?php $link_next = get_next_posts_link(); echo $link_next ?>"><div class="red_box"></div></a> 

任何人都知道正確的代碼?

+0

這是你在找什麼? https://codex.wordpress.org/Function_Reference/get_next_post – Matthijs

+0

@Matthijs我看了一下,但它不會幫助我 –

回答

0

我找到了解決方案。一個可能的解決方案可能是這樣的:

<?php $prev = get_permalink(get_adjacent_post(false,'',false)); 
    if ($prev != get_permalink()) { ?><a href="<?php echo $prev; ?>"><div class="arrow_left"></div></a><?php } ?> 

    <?php $next = get_permalink(get_adjacent_post(false,'',true)); 
    if ($next != get_permalink()) { ?><a href="<?php echo $next; ?>"><div class="arrow_right"></div></a><?php } ?> 
相關問題