【问题标题】:How to exclude last post from blog page in wordpress如何从wordpress的博客页面中排除最后一篇文章
【发布时间】:2013-09-11 14:39:18
【问题描述】:

我曾经在 wordpress 中写过几篇博客文章。我已经完全更新了 10 个帖子,并且完美地显示了 10 个帖子。

我的问题是,

我只需要显示 9 个帖子。最后更新的帖子不应显示在网站上。我需要代码来排除第 10 个帖子的最新帖子。我需要将代码放在functions.php上。

谁能帮帮我。

提前致谢。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    只需从admin pannel 转到您的settings,然后单击reading,然后将blog post at most 更改为9

    或者以编程方式你可以尝试

     $latestPosts = new WP_Query( array(
                            'posts_per_page'            => 9, 
                            'orderby'                   => 'date',
                            'order'                     => 'DESC',
                          )); // end query
    
      while ($latestPosts->have_posts()) : $latestPosts->the_post();
    

    【讨论】:

    • 嗨 gautam,谢谢你的回复。此答案仅显示 9 个帖子。但我需要排除(删除)最后一个帖子。
    • 我有左右两列。在左侧部分,我编写了代码来显示最后一篇文章(第 10 篇文章)的一篇文章。在右侧部分,wordpress 代码会自动显示 10 个帖子(我没有编写代码)。它显示了所有 10 个帖子。我不需要最后一篇文章(第 10 篇文章),因为它已经在左侧部分了。
    • 所以使用我的第二个ans'
    • 我需要在functions.php中使用它
    猜你喜欢
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多