简体   繁体   中英

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 . You might want to try echo for both values, so your code becomes:

<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.

If that is not working, please provide us a Minimal, Complete, and Verifiable example because we might use other input than you are using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM