In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to manually customize the number of wordpress articles displayed, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
WordPress shows the number of articles per page in the background reading settings specified, will be applied to the blog list page (usually the home page), search page, tab page, category page and time index page, add these pages with different structure, for example, some show the title and summary, some show only the title, then specify the same number of pages does not apply to each page. To specify the number of articles to display per page according to the page type, you need to write code to implement it.
Recommended method
Modify the number of articles displayed per page, that is, modify the posts_per_page parameter, put the following code into functions.php, the code is from WordPress Answers.
Function custom_posts_per_page ($query) {if (is_home ()) {$query- > set ('posts_per_page',8); / / Home page displays 8 articles per page} if (is_search ()) {$query- > set (' posts_per_page',-1) / / search page displays all matching articles, no pagination} if (is_archive ()) {$query- > set ('posts_per_page',25); / / archive displays 25 articles per page} / / endif} / / function / / this adds the function above to the' pre_get_posts' action add_action ('pre_get_posts','custom_posts_per_page')
Through WordPress's condition tag, you can extend this code at will.
Methods that are not recommended
It is not recommended to modify the theme template directly, such as using query_posts to change the number of articles per page before the main index.php loop
Query_posts ('posts_per_page=5')
Disadvantages:
First, increase the number of queries.
Second, the flexibility is not high, if the classification, tags have their own templates, but also need to repeat query_posts tricks in those templates.
Third, you need to be very careful when using query_posts. If you forget to restore global variables, you may have an inexplicable error.
The above is how to manually customize the number of wordpress articles displayed, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.