Home CMS Tutorial WordPress How to get the list of pinned articles in WordPress

How to get the list of pinned articles in WordPress

Dec 07, 2019 am 11:00 AM
wordpress

How to get the list of pinned articles in WordPress

#How to get the list of pinned articles in wordpress?

In WordPress, maybe you want to call the set specified article list. How to implement this function? The implementation method is introduced below, please refer to it

Recommended: "WordPress Tutorial"

First of all, you need to understand the query_posts function. The function of this function is to retrieve, select, and sort articles, and use the selected and sorted articles in the subsequent LOOP loop. For example:

The code is as follows

<?php
query_posts(&#39;posts_per_page=10&ignore_sticky_posts=1&orderby=rand&#39;);
while(have_posts()):the_post();
echo &#39;<li>&#39;;the_title();echo &#39;</li>&#39;;
endwhile;
wp_reset_query();
Copy after login

will randomly list the title of an article. As for the specific parameters of query_posts, please refer to the development manual.

Next, we need to select the top article list by adjusting the parameters of query_posts.

The code is as follows:

$query_post = array(
&#39;posts_per_page&#39; => 10,
&#39;post__in&#39; => get_option(&#39;sticky_posts&#39;),
&#39;caller_get_posts&#39; => 1
);
query_posts($query_post);
?>
<ul style="display:none;">
<?php while(have_posts()):the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php
wp_reset_query();
Copy after login

The parameters are placed in $query_post in the form of an array. The key parameters are 'post__in' =>get_option('sticky_posts') and 'caller_get_posts' => ; 0.

'post__in' => get_option('sticky_posts') determines that the LOOP calls the list of sticky articles. The function of 'caller_get_posts' is to exclude non-specified articles, that is, no other articles will be displayed except the top articles. (Without adding, if the pinned article entry is less than the value specified by 'posts_per_page', the latest article will be used to replace it.)

The above is the detailed content of How to get the list of pinned articles in WordPress. 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 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)

PHP vs. Flutter: The best choice for mobile development PHP vs. Flutter: The best choice for mobile development May 06, 2024 pm 10:45 PM

PHP and Flutter are popular technologies for mobile development. Flutter excels in cross-platform capabilities, performance and user interface, and is suitable for applications that require high performance, cross-platform and customized UI. PHP is suitable for server-side applications with lower performance and not cross-platform.

Does wordpress need to be registered? Does wordpress need to be registered? Apr 16, 2024 pm 12:07 PM

WordPress requires registration. According to my country's "Internet Security Management Measures", websites that provide Internet information services within the country must register with the local provincial Internet Information Office, including WordPress. The registration process includes steps such as selecting a service provider, preparing information, submitting an application, reviewing and publishing, and obtaining a registration number. The benefits of filing include legal compliance, improving credibility, meeting access requirements, ensuring normal access, etc. The filing information must be true and valid, and must be updated regularly after filing.

PHP Redis caching applications and best practices PHP Redis caching applications and best practices May 04, 2024 am 08:33 AM

Redis is a high-performance key-value cache. The PHPRedis extension provides an API to interact with the Redis server. Use the following steps to connect to Redis, store and retrieve data: Connect: Use the Redis classes to connect to the server. Storage: Use the set method to set key-value pairs. Retrieval: Use the get method to obtain the value of the key.

Does wordpress require code? Does wordpress require code? Apr 16, 2024 pm 12:00 PM

Yes, WordPress is a CMS that allows users to manage websites without coding. However, advanced features and customizations may require some coding knowledge, including themes, plugins, widgets, custom post types, and functions. Code level requirements vary depending on the goals of the implementation, typically no code is required for basic functionality, but basics of HTML, CSS, and PHP are required for advanced customization.

WordPress site file access is restricted: Why is my .txt file not accessible through domain name? WordPress site file access is restricted: Why is my .txt file not accessible through domain name? Apr 01, 2025 pm 03:00 PM

Wordpress site file access is restricted: troubleshooting the reason why .txt file cannot be accessed recently. Some users encountered a problem when configuring the mini program business domain name: �...

Is wordpress self-service website building a saas website building? Is wordpress self-service website building a saas website building? Apr 16, 2024 am 11:42 AM

Yes, WordPress self-service website building is a SaaS website building, which is cloud-based, monthly subscription, easy to use and scalable. As a SaaS website builder, it provides advantages such as ease of use, affordability, scalability, security, and technical support.

Is WordPress from Microsoft? Is WordPress from Microsoft? Apr 16, 2024 am 11:51 AM

No, WordPress is not owned by Microsoft. WordPress is an open source content management system managed by the WordPress Foundation.

WordPress background crashes and prompts 'out of memory'. How to troubleshoot and solve it? WordPress background crashes and prompts 'out of memory'. How to troubleshoot and solve it? Apr 01, 2025 am 08:00 AM

Methods to troubleshoot WordPress background crash and debug mode failure WordPress website suddenly crashes after running stable, and a few seconds after entering the background...

See all articles