小工具      在线工具  汉语词典  dos游戏  css  js  c++  java

如何从WordPress循环中排除粘性帖子

java,python,wordpress,php,html 额外说明

收录于:18天前

置顶帖 are a great way to highlight your featured content. However, there are certain places on your website where you don’t need sticky posts to be on the top. WordPress can not guess this so you need to explicitly tell WordPress to exclude sticky posts from a custom loop. In this article, we will show you how to completely exclude sticky posts from the loop in WordPress, and we will also show you how you can take away the sticky feature of the post, so it still shows in their natural order.

便利贴是突出显示特色内容的好方法。 但是,您网站上的某些位置不需要在顶部放置粘性帖子。 WordPress无法猜测这一点,因此您需要明确告诉WordPress从自定义循环中排除粘性帖子。 在本文中,我们将向您展示如何从WordPress的循环中完全排除粘性帖子,并且还将向您展示如何删除帖子的粘性功能,使其仍然按其自然顺序显示。

如何带走岗位的黏性 How to take away the Sticky Ability of the Post

When you are displaying most recent posts in a tab, you do not want the sticky posts to stay sticky. If you do not remove the sticky feature, the recent posts area would be useless as all your sticky posts will crowd this area. This is where query_posts feature comes in handy.

当您在选项卡中显示最新帖子时,您不希望粘性帖子保持粘性。 如果您不删除粘性功能,则最近的帖子区域将无用,因为您所有的粘性帖子都将拥挤该区域。 这是query_posts功能派上用场的地方。

为此,您需要将循环更改为如下所示:

为此,您需要将循环更改为以下内容:


<?php
$args = array(
	'posts_per_page' => 10,
	'ignore_sticky_posts' => 1
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
?>

此代码忽略帖子是粘性的并以正常顺序显示帖子。使用此代码,您的置顶帖子将出现在循环中,但它们不会放置在顶部。

此代码忽略置顶的帖子并按正常顺序显示帖子。使用此代码,您的置顶帖子将出现在循环中,但不会放置在顶部。

Sticky posts displayed in normal order
从循环中完全排除粘性帖子 Completely exclude Sticky posts from the Loop

如果您在滑块中使用粘性帖子,那么有时您可能希望将粘性帖子完全排除在循环之外。您所要做的就是编辑自定义循环以与之匹配:

如果您在滑块中使用卡片,有时您可能希望将自己的卡片从循环中排除。您需要做的就是编辑自定义循环以匹配此:


<?php
$the_query = new WP_Query( array( 'post__not_in' => get_option( 'sticky_posts' ) ) );
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
?>

This code will not display any sticky posts in the post loop. For more tips on modifying WordPress themes, check out our WordPress 主题备忘单 for beginners.

此代码不会在发布循环中显示任何粘性发布。 有关修改WordPress主题的更多提示,请查阅针对初学者的WordPress 主题备忘单

Source: WP 法典

资料来源: WP 法典

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

. . .

相关推荐

额外说明

mysql发现重复数据

  https://blog.51cto.com/13689359/2401599?source=dra   MySQL里查询表里的重复数据记录: 先查看重复的原始数据: 场景一:列出username字段有重读的数据 1 2 3 select usern

额外说明

PostgreSQL并发控制事务隔离

PostgreSQL 并发控制 事务隔离 SQL标准定义了四种隔离级别 脏读 不可重复读 幻读 序列化异常 SQL 标准和 PostgreSQL 实现的事务隔离级别 读已提交隔离级别 可重复读隔离级别 可序列化隔离级别 SQL标准定义了四种隔离级别 最严

额外说明

性能测试、python内存分析工具-memray

Memray是一个由彭博社开发的、开源内存剖析器;开源一个多月,已经收获了超8.4k的star,是名副其实的明星项目。今天我们就给大家来推荐这款python内存分析神器。 ​ Memray可以跟踪python代码、本机扩展模块和python解释器本身中内

额外说明

linux学习笔记初级版(Red Hat Enterprise 5.X)

1 怎么用命令查看本地计算机ip地址 ex:  /sbin/ifconfig -a  或者ifconfig -a 2 怎么样切换root与普通用户xiao Cmd:su ex:su xiao/su root   3 怎样使用命令帮助 ex: reboot

额外说明

day15---(01)获取阿里云视频播放凭证接口

1、 在service_vod模块创建接口 在service_vod的com/ atguigu/vodservice/controller/VideoController里添加根据视频id获取视频播放凭证。 package com.atguigu.vod

额外说明

Python 第四节 第七课

[toc] 集合 集合是无序可变, 元素不能重复. 实际上, 集合底层是字典实现, 集合的所有元素都是字典中的 "键对象", 因此是不能重复的且唯一的. 集合的创建和删除 1. 使用 {} 创建集合对象, 并使用 add() 方法添加元素     >>>

额外说明

【C#基础1-6】C#的数组和字符串

一、引言 上篇文章【1-5C#基础】C#的条件运算循环分支 本篇介绍C#的数组和字符串 二、数组(Array) 简介 数组是一个存储相同类型元素的固定大小的顺序集合。数组是用来存储数据的集合,通常认为数组是一个同一类型变量的集合。 声明数组变量并不是声明

额外说明

【Go 基础篇】Go语言进制与进制转换:探索数据的不同表示方式

介绍 计算机科学中,进制是一种表示和处理数据的方式。在Go语言(Golang)编程中,了解进制及其转换是非常重要的基础知识。本篇博客将深入探讨Go语言中的进制表示、进制转换以及相关应用,帮助您理解如何在不同进制之间进行转换,以及如何利用进制知识处理数据。

额外说明

开源协议浅谈

前言 从 1985 年 Richard Stallman 成立 Free Software Found 开始, 开源就如雨后春笋,发展得如火如荼。小到java 或js 的一个组件,大到 linux 操作系统。开源软件的也从仅仅的开源自由进化到创新,编译,

额外说明

发布微软 AJAX CDN

【原文地址】Announcing the Microsoft AJAX CDN | 宣布微软 AJAX CDN  【原文发表日期】 Tuesday, September 15, 2009 11:46 PM 今天早些时候,ASP.NET开发团队推出了一个新

ads via 小工具