在自定义最近的帖子页面上显示下一页/上一页按钮 Wordpress.



我正在为客户构建一个Wordpress主题,我制作了一个特定的"新闻"页面,显示最近的帖子(没有类别(。我已将这些设置为每页最多 5 个帖子,现在我还想添加导航到旧帖子的选项。但是,我找到的大多数解决方案根本不适合我的情况。我的PHP知识有限,所以很可能我只是错误地实现了可能的解决方案。我当前在相关页面上的 php:

<?php
$args         = array(
    'posts_per_page' => '5',
    'paged' => $paged
);
$recent_posts = wp_get_recent_posts($args);
$text         = apply_filters('the_excerpt', get_post_field('post_excerpt', $post_id));
$post_date    = get_the_date('j F, Y');
foreach ($recent_posts as $recent) {
    echo '<li>
                                <div class="nieuwsimg" style="background-image:url(' . get_the_post_thumbnail_url($recent["ID"]) . ')"></div>
                                <div class="nieuwstekst">
                                <p style="color:#fff;margin-top:20px;margin-bottom:-15px;">' . get_the_date('j F, Y', $recent["ID"]) . '</p>
                                <h3><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"] . '</a> </h3>
                                <p><a href="' . get_permalink($recent["ID"]) . '">' . wp_trim_words(get_post_field('post_content', $recent["ID"]), 50, '...') . '</a>
                                <a href="' . get_permalink($recent["ID"]) . '">Lees verder</a>
                                </p></div>
                                </li><hr> ';
}
?>

任何帮助将不胜感激!

你可以检查wp_get_recent_posts函数这里它使用的是:号码柱,而不是使用posts_per_page

最新更新