wordpress - Wordpress 发布上一个/下一个链接,仅在上一个上带有图像和标题
问题描述
我正在尝试为上一篇文章和下一篇文章添加箭头图像,但我希望帖子标题仅显示在上一篇文章中,而不是下一篇文章中。
这是我的代码 -
<div class="nav-next"><?php previous_post_link('%link', ' <img src="/wp-content/themes/azure-basic-child/images/larrow.png" />' , ' %title '); ?></div>
<div class="nav-previous"><?php next_post_link('%link', ' <img src="/wp-content/themes/azure-basic-child/images/rarrow.png" /> '); ?></div>
这是页面 - https://lucchesipgh.org/word-of-the-week/
我那里有箭头,但没有以前的帖子标题。
解决方案
您可以使用get_previous_post()
和get_next_post()
(https://codex.wordpress.org/Function_Reference/get_previous_post / https://codex.wordpress.org/Function_Reference/get_next_post)。
这些函数将返回帖子对象(https://codex.wordpress.org/Class_Reference/WP_Post)。
如果您需要标题使用echo $post->title
(未过滤)或the_title($post->ID)
(过滤)。要获得永久链接,请使用echo get_the_permalink($post->ID)
.
推荐阅读
- python - 如何根据级别将 agg 应用于具有不同功能的多索引数据框?
- node.js - Stripe Connect PaymentIntent 错误:没有这样的 payment_intent
- c# - 数据网格视图中的参数超出范围异常
- java - 排序对列表java
- javascript - 无法在可折叠的力有向图 d3.js 中输入文本
- php - 如果没有从管理端添加图像,则隐藏 img 标签
- python - ModuleNotFoundError 在从 importlib 导入的模块上使用“经典”导入
- php - 在 PHP 中读取多维数组
- javascript - 如果没有从 URL 调用返回响应,则从 URL 获取响应并停止进一步处理的最佳方式
- python - python 2.7 与 3.7 中的 SIGINT 信号处理程序行为差异