Table of Contents
1. How to set the article to the top in WordPress?
2. Add the words “sticky” to the title
3. The pinned article does not display the article summary
4. Pin it to the top Add a border or background to the article
Home CMS Tutorial WordPress A brief analysis of how to pin articles to the top in WordPress? How to distinguish it from ordinary articles?

A brief analysis of how to pin articles to the top in WordPress? How to distinguish it from ordinary articles?

Mar 13, 2023 pm 08:18 PM
php wordpress

How to set the article to the top in WordPress? How to distinguish pinned articles? The following article will introduce to you several ways to distinguish pinned articles in WordPress. I hope it will be helpful to you!

A brief analysis of how to pin articles to the top in WordPress? How to distinguish it from ordinary articles?

Many blogs have their own pinned articles. By default, WP only ranks their pinned articles at the front. In addition to the position difference, it is different from other articles. There is no difference. So how can we tell them apart? I have several methods here:

1. How to set the article to the top in WordPress?

I believe many friends don’t know that WordPress itself has the function of pinning articles, and it is really a waste to look for plug-ins to implement the pinning function. I think it is necessary to explain how to pin articles. . Setting the article to the top in WordPress is very simple. Open the article editing page and click the Publish column in the right column to set it, as shown in the picture:

A brief analysis of how to pin articles to the top in WordPress? How to distinguish it from ordinary articles?

2. Add the words “sticky” to the title

In fact, the function we will use in this article is only one is_sticky(), this function is used to determine Whether this article is a pinned article. Pinned articles are generally only displayed on the home page, so now open index.php in your theme directory, search for: the_title(); and change it to:

the_title(); if( is_sticky() ) echo &#39;  <span style="color:red;">置顶</span>&#39;;
Copy after login

3. The pinned article does not display the article summary

Also open index.php, search: the_content or the_excerpt, give It adds a judgment so that the pinned article does not display the summary, such as:

if( !is_sticky() ) the_content(....);
Copy after login

or

if( !is_sticky() ) the_excerpt(....);
Copy after login

4. Pin it to the top Add a border or background to the article

This method does not need to determine whether it is a pinned article, we only need to add a CSS style to it. Open index.php in the theme directory and find the div where each article is located. General theme search: class="post" This div is the div where each article is located. We now add a class to this div, such as

Change to (class="post" in the following code can be removed):

<div <?php post_class(); ?> class="post">
Copy after login

If it is a pinned article, this div will be automatically added Add a class .sticky. Now we open style.css in the theme directory and add the class attribute:

.sticky {
   background: #ff0000;
   border: 1px solid #ccc;
}
Copy after login

In this way, the sticky article will have a background and border. Isn’t it ugly? ? You can modify this class attribute as needed to obtain the effect you are satisfied with.

Recommended learning: "WordPress Tutorial"

The above is the detailed content of A brief analysis of how to pin articles to the top in WordPress? How to distinguish it from ordinary articles?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1667
14
PHP Tutorial
1273
29
C# Tutorial
1255
24
How to adjust the wordpress article list How to adjust the wordpress article list Apr 20, 2025 am 10:48 AM

There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

How to build a website for wordpress host How to build a website for wordpress host Apr 20, 2025 am 11:12 AM

To build a website using WordPress hosting, you need to: select a reliable hosting provider. Buy a domain name. Set up a WordPress hosting account. Select a topic. Add pages and articles. Install the plug-in. Customize your website. Publish your website.

How to import the source code of wordpress How to import the source code of wordpress Apr 20, 2025 am 11:24 AM

Importing WordPress source code requires the following steps: Create a sub-theme for theme modification. Import the source code and overwrite the files in the sub-topic. Activate the sub-theme to make it effective. Test the changes to make sure everything works.

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

How to view the front-end of WordPress How to view the front-end of WordPress Apr 20, 2025 am 10:30 AM

You can view the WordPress front-end by logging into the dashboard and switching to the View Sites tab; automate the viewing process with a headless browser; installing the WordPress plugin to preview the front-end within the dashboard; viewing the front-end via a local URL (if WordPress is set locally).

What happens if session_start() is called multiple times? What happens if session_start() is called multiple times? Apr 25, 2025 am 12:06 AM

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

How to register a wordpress account How to register a wordpress account Apr 20, 2025 am 11:45 AM

To create an account on WordPress, simply visit its website, select the registration option, fill in the registration form, and verify your email address. Other ways to register include using a Google account or Apple ID. The benefits of signing up include creating a website, gaining features, joining the community, and gaining support.

How to cancel the editing date of wordpress How to cancel the editing date of wordpress Apr 20, 2025 am 10:54 AM

WordPress editing dates can be canceled in three ways: 1. Install the Enable Post Date Disable plug-in; 2. Add code in the functions.php file; 3. Manually edit the post_modified column in the wp_posts table.

See all articles