简体   繁体   English

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

[英]Show next/previous page buttons on custom recent posts page Wordpress

I'm building a Wordpress theme for a client and I amde a specific "news" page which displays recents posts (no category). 我正在为客户构建一个Wordpress主题,并且修改了一个特定的“新闻”页面,该页面显示了最近的帖子(没有类别)。 I've set these to a maximum of 5 posts per page and now I'd like to add the option to navigate to older posts as well. 我将这些设置为每页最多5个帖子,现在我想添加一个选项以导航至较早的帖子。 However, most solutions I found simply do not work for my situation. 但是,我发现的大多数解决方案都不适合我的情况。 My PHP knowledge is limited, so it might very well be the case that I simply implement possible solutions wrong. 我的PHP知识是有限的,因此很可能我只是错误地实现了可能的解决方案。 My current php on the page in question: 我目前在该页面上的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> ';
}
?>

Any help would be greatly appreciated! 任何帮助将不胜感激!

您可以在此处检查wp_get_recent_posts函数它正在使用:numberposts,而不使用posts_per_page

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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