[英]Wordpress next previous post
code is not running. 代码未运行。 the name does not appear.
名称不出现。 I looked at all the sites but couldn't find anything
我查看了所有站点,但找不到任何东西
<?php
$prev_post = get_previous_post();
$prev_title = strip_tags(str_replace('"', '', $prev_post->post_title));
$prev_ID = strip_tags(str_replace('"', '', $prev_post->ID));
$prev = previous_posts_link($prev_ID);
$prevlink = get_permalink($prev_ID);
?>
<div class="previuos">
<a href="<?php echo $prevlink ?>"> <?php print_r($prev_post->post_title) ?></a>
</div>
<?php
$next_post = get_next_post();
$next_title = strip_tags(str_replace('"', '', $next_post->post_title));
$next_id = strip_tags(str_replace('"', '', $next_post->ID));
$next = next_posts_link($next_id);
$nextlink = get_permalink($next_id);
?>
<div class="next">
<a href="<?php echo $nextlink ?>"> <?php echo $next_title; ?></a>
</div>
I see a difference in both lines with an <a>
-tag, because in the first one you write print_r($prev_post->post_title)
, but the second one has echo $next_title
. 我看到两行都有
<a>
-tag的区别,因为在第一行中您编写了print_r($prev_post->post_title)
,但是第二行中有echo $next_title
。 You might want to try echo
for both values, so your code becomes: 您可能想对两个值都尝试
echo
,因此您的代码变为:
<a href="<?php echo $prevlink ?>"> <?php echo($prev_title); ?></a>
The method print_r()
is better suited when you want to print output for an array, so echo
is probably what you need here, because you expect text, not an array. 当您要为数组打印输出时,方法
print_r()
更适合,因此echo
可能是您需要的,因为您希望输入文本而不是数组。
If that is not working, please provide us a Minimal, Complete, and Verifiable example because we might use other input than you are using. 如果这不起作用,请提供一个最小,完整和可验证的示例,因为我们可能会使用您输入之外的其他输入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.