简体   繁体   中英

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). 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. 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. My current php on the page in question:

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

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