dsjbest2014 2019-04-01 13:59
浏览 136

在自定义最近的帖子页面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!

  • 写回答

1条回答 默认 最新

  • dongling5411 2019-04-01 15:03
    关注

    You can check wp_get_recent_posts function here It is using : numberposts, and not use posts_per_page

    评论

报告相同问题?