[更新|较旧] 如果我点击较新,则会加载较新的最近帖子。 如果我点击较旧的,则将加载下一篇最近的帖子。 我是 WordPress 新手。谁能给我一个在这段代码中实现导航的想法。如下所示?
<?php
$args = array( 'numberposts' => '3' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ) {
echo '<li style="font-weight:700;"><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a> </li> ';
echo '<li>' .wpautop(wp_trim_words($recent["post_content"], 15)). '</li>';
}
?>
最佳答案
你想要的是使用这两个函数:get_next_post和 get_previous_post
$next_post = get_next_post();
$prev_post = get_previous_post();
关于php - 如何在WordPress最近的帖子中添加导航?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25969577/