wordpress排除分类_如何从WordPress帖子循环中排除最新帖子

wordpress排除分类

Excluding latest posts from the loop and/or offset posts in the loop is one of the things that comes in handy when editing or designing themes. In this article we will show you how you can use the offset parameter in wp_query function to exclude latest posts from the WordPress post loop.

在编辑或设计主题时,方便的事情之一就是从循环中删除最新的帖子和/或在循环中添加偏移的帖子。 在本文中,我们将向您展示如何在wp_query函数中使用offset参数从WordPress帖子循环中排除最新帖子。

First you will need to find the loop that you are working with. Then you will need to add the following parameter:

首先,您需要找到正在使用的循环。 然后,您将需要添加以下参数:

query_posts('posts_per_page=5&offset=1');

query_posts('posts_per_page = 5&offset = 1');

This query is telling the loop to only display 5 posts which follow the most recent post (1). The important part in this code is “offset” and this magic word is doing the whole thing.

该查询告诉循环仅显示5条帖子,这些帖子紧随最新的帖子(1)。 该代码中的重要部分是“偏移”,而这个神奇的词正在做整个事情。

Your loop code should look like:

您的循环代码应如下所示:

<?php
query_posts('posts_per_page=6&offset=1');
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>

<?php
query_posts('posts_per_page = 6&offset = 1');
if(have_posts()):while(have_posts()):the_post();
?>

This should be it. If you have any questions feel free to ask via comments.

应该是这样。 如果您有任何问题,请随时通过评论提问。

Source: WP Codex

资料来源: WP Codex

翻译自: https://www.wpbeginner.com/wp-themes/how-to-exclude-latest-post-from-the-wordpress-post-loop/

wordpress排除分类

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值