The number of articles displayed per page is different for different categories of wordpress
//Different paging display quantity called by different classifications function tx_wp_filter_pre_get_posts($query) { If ($query ->is_main_query()) {//Judge whether the main query is $num = ''; If (is_category()) {//Judge whether to classify $cat_ID = get_queried_object_id(); //Get the classification ID if (get_option('cat-pagenum-' . $cat_ID) {//Judge whether the category custom field has a value $num = get_option('cat-pagenum-' . $cat_ID); $query->set('posts_per_page', $num); //Assign a value to the number of articles per page in the main loop data } } } return $query; } add_action('pre_get_posts', 'tx_wp_filter_pre_get_posts'); //Hang the hook
//Different paging display quantity called by different classifications function tx_wp_filter_pre_get_posts($query) { If ($query ->is_main_query()) {//Judge whether the main query is $num = ''; If (is_category (array (1)) {//The number 1 is the specified classification id $num = 2; //The number 2 is the number of articles per page, which can be modified arbitrarily but must be an integer $query->set('posts_per_page', $num); //Assign a value to the number of articles per page in the main loop data } } return $query; } add_action('pre_get_posts', 'tx_wp_filter_pre_get_posts'); //Hang the hook
Can't find a tutorial that can solve your problem?
-
Charging zblogphp template The 9th zblog enterprise theme of Tianxing Studio is submitted with its own form, adding multilingual function suitable for foreign trade zero 2019-12-11 nineteen thousand nine hundred and thirty-nine Price: four hundred and sixty-eight Online purchase -
Charging zblogphp template Tianxing Studio ppt download template is suitable for sites with resources to sell vips one 2019-10-03 fifteen thousand two hundred and nineteen Price: one hundred and ninety-nine Online purchase -
Wordpress template Tianxing Studio wordpress download station theme is applicable to software/app/game and other download stations zero 2022-05-06 sixteen thousand five hundred and sixty-three Price: three hundred and fifty-five Online purchase -
Charging zblogphp template Tianxing Studio zblogphp enterprise theme 6 Self configurable atmosphere zblog enterprise theme two 2018-06-26 fifty-one thousand seven hundred and seven Price: two hundred and fifty-eight Online purchase
Related recommendations
-
The number of articles displayed per page is different for different categories of wordpress 04-24 -
Wordpress gets the top-level classification ID of the current classification and calls the subcategory 04-15 -
Functions and Switches of Wordpress Development Mode (DEBUG) 04-02 -
Wordpress obtains the website title of the previous article and the next article separately 03-22 -
The post returns 404 after calling "wp blog header". The cause and solution of the problem 03-05 -
The code and steps for creating a new data table in WordPress 03-04 -
Solution to the problem that Wordpress calls the article content label and the article content does not break lines 02-22 -
The solution to the time zone problem when wordpress uses strtotime 02-17 -
Wordpress related article function code example 02-13 -
Wordpress calls specified field article data+specified field sorting 12-30
welcome you Comment: Cancel Reply
-
Zblog enterprise theme -
Zblog image theme -
Zblog resource topic -
Zblog CMS topic -
Wordpress template -
Zblog video theme -
Zblog Taobao guest theme -
Zblog navigation topic
Select a theme?
-
Latest articles -
Hot article ranking -
Most Comments
-
one Tianxing Studio multilingual translation plug-in can automatically translate up to 12 languages for foreign trade sites 06-23 -
two Detailed steps and screenshots of Youdao Cloud Translation to obtain appid and seckey 06-22 -
three The asynchronous notification page after Alipay payment prompts "Payment signature verification failed, please contact the administrator! "Causes and solutions 05-08 -
four Screenshot of AliCloud OSS configuration item acquisition steps, including ID and Secret, regional node endpoint, storage space bucket and resource access domain name 04-14 -
five The cause and solution of verification code error is always prompted in the background of zblog login 03-01 -
six Zblog uses api to submit post data, prompting the reason and solution of 419 error 02-23 -
seven Tianxing Studio 2025 Spring Festival Holiday Announcement 01-25 -
eight Tutorial of setting "WeChat notification" function of Tianxing user center plug-in 11-09 -
nine Alibaba Cloud 2024 Double 11 Event is recommended to participate through the website link and give away vouchers on the website 11-05
-
Label aggregation -
×1 Zblog account ×4 Preferential activities ×1 Very slow ×1 Zblog search template ×1 Limited time promotion ×1 administrators ×1 Nicescroll.js ×2 Christmas ×3 301 Redirect ×1 Specify Article ×4 Dedecms template ×1 Site Map ×2 Zbp template ×1 hover ×1 Next ×1 Picture with alt ×1 Developer Mode ×1 Label optimization ×1 WeChat 5.0 ×1 specified
Latest comments
-
Tianxing Studio 02-08 No restrictions Commented on: Tianxing Studio zblog Taoke theme is suitable for promoting websites with content -
visitor 02-08 Do you think the users of zblog Taoke must be enterprises? Commented on: Tianxing Studio zblog Taoke theme is suitable for promoting websites with content -
kevel 11-09 Guys, throw away some demo stations other than the authors. I want to see your layout settings Commented on: Template of zblog navigation station of Tianxing Studio with news, pictures and Taoke module -
Interesting life 10-22 I have always wanted to develop the function of zblog. I don't know whether it is enough Commented on: Code of zblog calling the latest comment (the latest message) -
visitor 10-16 When publishing an article, how to change the default status, such as changing to the default approval status? Commented on: Zblog article management: zblog creates and publishes articles