簡體   English   中英

在自定義的最新帖子頁面上顯示下一頁/上一頁按鈕

[英]Show next/previous page buttons on custom recent posts page 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函數它正在使用:numberposts,而不使用posts_per_page

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM