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('posts_per_page=10&ignore_sticky_posts=1&orderby=rand'); while(have_posts()):the_post(); echo '<li>';the_title();echo '</li>'; endwhile; wp_reset_query();
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( 'posts_per_page' => 10, 'post__in' => get_option('sticky_posts'), 'caller_get_posts' => 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();
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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.

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.

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.

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: troubleshooting the reason why .txt file cannot be accessed recently. Some users encountered a problem when configuring the mini program business domain name: �...

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.

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

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...
