我最近尝试了上一篇文章和下一篇文章按钮链接。我在网站的左右两侧使用图像。它工作得很好。但我不知道怎么做
For Example:
<div class="alignleftfp">
<?php next_post(\'%\', \'<img class="imgalign" src="\' . WP_CONTENT_URL . \'/uploads/1.png" alt="Next" /> \', \'no\');
?>
</div>
<div class="alignrightfp">
<?php previous_post(\'%\', \'<img class="imgalign" src="\' . WP_CONTENT_URL . \'/uploads/1.png" alt="Next" /> \', \'no\');
?>
</div>
是否可以在文章的每个底部显示上一篇文章和下一篇文章的链接以及标题下的链接。这是屏幕截图。
EDITED:
查看我编辑的代码。
<?php
function nextprev() {
?>
<div class="alignleftfp">
<?php next_post_link(\'%link\', \'<img class="imgalign" src="\' . WP_PLUGIN_URL . \'/testplugin/assets/type1/5.png" alt="Next" /> %title\'); ?>
</div>
<div class="alignrightfp">
<?php previous_post_link(\'%link\', \'%title <img class="imgalign" src="\' . WP_PLUGIN_URL . \'/testplugin/assets/type1/6.png" alt="Next" />\'); ?>
</div>
<?php
$content = get_the_content();
echo $content;
}
add_action(\'the_content\',\'nextprev\');
?>
最合适的回答,由SO网友:Krzysiek Dróżdż 整理而成
我想你可以这样做:
<div class="alignleftfp">
<?php next_post_link(\'%link\', \'<img class="imgalign" src="\' . WP_CONTENT_URL . \'/uploads/1.png" alt="Next" /> %title\'); ?>
</div>
<div class="alignrightfp">
<?php previous_post_link(\'%link\', \'%title <img class="imgalign" src="\' . WP_CONTENT_URL . \'/uploads/1.png" alt="Next" />\'); ?>
</div>
附言:你不应该使用
next_post
/
previous_post
函数-它们已弃用。
EDIT
只需阅读
the_content
筛选文档。它不应该有任何回声。它应该返回它的值。因此,您的函数应该如下所示:
function nextprev($content) {
ob_start(); ?>
<div class="alignleftfp">
<?php next_post_link(\'%link\', \'<img class="imgalign" src="\' . WP_PLUGIN_URL . \'/testplugin/assets/type1/5.png" alt="Next" /> %title\'); ?>
</div>
<div class="alignrightfp">
<?php previous_post_link(\'%link\', \'%title <img class="imgalign" src="\' . WP_PLUGIN_URL . \'/testplugin/assets/type1/6.png" alt="Next" />\'); ?>
</div>
<?php $my_next_prev = ob_get_contents(); ob_end_clean();
return $content . $my_next_prev;
}
add_action(\'the_content\',\'nextprev\');