【问题标题】:Show next/previous page buttons on custom recent posts page Wordpress在自定义最近帖子页面 Wordpress 上显示下一页/上一页按钮
【发布时间】:2019-08-22 17:29:00
【问题描述】:

我正在为客户构建一个 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> ';
}
?>

任何帮助将不胜感激!

【问题讨论】:

    标签: php wordpress pagination posts


    【解决方案1】:

    您可以查看 wp_get_recent_posts 功能 here 它使用的是:numberposts,而不是使用posts_per_page

    【讨论】:

    • 我将其更改为 numberposts,这并没有真正解决任何问题,因为它没有添加所需的上一页/下一页按钮。
    • 您使用 ajax 加载最近的页面或仅使用 php 的页面?
    • 你可以添加 $paged = $_GET['page'] 并且下一个链接是: currentlink?page=
    • 我没有使用 ajax,只是 php。
    • 实施您的建议只会重新加载页面以显示我之前看到的相同帖子,而不是以前的帖子。问题是我不在“页面”上。您的建议尝试将 1 添加到不存在的当前页码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-04
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多