WP:上一个/下一个帖子作为< a> -tag中的链接 [英] WP: Previous/next post as link in <a>-tag

查看:66
本文介绍了WP:上一个/下一个帖子作为< a> -tag中的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Wordpress中的自定义帖子类型:是否可以将导航功能集成到元素的< a> -标签中?

Custom Post Types in Wordpress: Is it possible to integrate a navigation functionality into the <a>-tag of an element ?

假设我们在 single-customposttype.php 文件中有一个彩色框.当您单击它时,必须显示自定义帖子类型的下一个帖子.

Let's say in the single-customposttype.php file I have a coloured box. When you click on it the next post of the custom post type must appear.

我尝试了此操作,但没有用:

I tried this, but it doesn't work:

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

有人知道正确的密码吗?

Anyone knows the correct code?

推荐答案

我找到了解决方案.可能的解决方案可能是这样的:

I found the solution. A possible solution can be something like this:

    <?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 } ?>

这篇关于WP:上一个/下一个帖子作为&lt; a&gt; -tag中的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆