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 next_post_link('%link','<div class="nav-next" title="<?php the_title();?>">Next Post</div>')?&g开发者_开发技巧t;
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?
Thanks.
There is no need for get_the_title. next_post_link already makes the title of the next post available, via %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:
<?php
next_post_link(
'%link',
'<div class="nav-next" title="'.get_the_title().'">Next Post</div>'
)?>
精彩评论