简体   繁体   English

如何将PHP代码放入wordpress分页功能(previous_post_link,next_post_link等)中?

[英]How to put PHP code in wordpress pagination function (previous_post_link,next_post_link,etc)?

I want to put PHP code in my pagination: 我想将PHP代码放入分页中:

<?php next_post_link('%link','<div class="nav-next" title="<?php the_title();?>">Next Post</div>')?>

However, the result is I got a text: "" instead of the real title post when I hover my pagination link. 但是,结果是,当我悬停我的分页链接时,我得到一个文本:“”,而不是真实的标题。

How to get my php code works inside that wordpress parameter? 如何让我的PHP代码在该wordpress参数内工作?

Thanks. 谢谢。

There is no need for get_the_title. 不需要get_the_title。 next_post_link already makes the title of the next post available, via %title next_post_link已通过%title使下一篇文章的标题可用

 next_post_link( '%link', '<div class="nav-next" title="%title">Next Post</div>' )

Use string concatenation and get_the_title() which returns the value rather than echoing it: 使用字符串串联和get_the_title()返回值而不是回显它:

<?php 
  next_post_link(
           '%link',
           '<div class="nav-next" title="'.get_the_title().'">Next Post</div>'
 )?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从next_post_link和previous_post_link(Wordpress)中排除某些类别? - How to exclude some Categories from next_post_link and previous_post_link (Wordpress)? 如何在简码中显示 previous_post_link () / next_post_link () - Wordpress - How to show previous_post_link () / next_post_link () in shortcode - Wordpress Wordpress:将if-else语句插入next_post_link()/ previous_post_link()参数? - Wordpress: Inserting if-else statement into next_post_link() / previous_post_link() parameters? Wordpress next_post_link / previous_post_link不属于同一类别 - Wordpress next_post_link/previous_post_link not staying in same category Wordpress:previous_post_link / next_post_link按字母顺序排列? - Wordpress: previous_post_link / next_post_link by alphabetical order? WordPress-next_post_link / previous_post_link提供文本而不是链接 - Wordpress - next_post_link/previous_post_link giving text instead of links 我在 single.php 中使用 previous_post_link() 和 next_post_link() 的单个帖子导航遇到问题,但不能使用帖子类型“post” - I am getting issues with my single Post navigation in single.php with previous_post_link() and next_post_link() is not working with post type "post" 使用html链接调用wordpress previous_post_link函数 - Calling wordpress previous_post_link function with an html link 将Google Analytics添加到Wordpress的next_post_link功能 - Adding Google Analytics to Wordpress' next_post_link function 从WordPress的功能获得页面标题previous_post_link() - obtaining page title from wordpress function previous_post_link()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM