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 has its own form to submit email reminders, etc zero 2019-12-11 nine thousand seven hundred and ninety-five Price: four hundred and eighty-eight Online purchase -
Charging zblogphp template Tianxing Studio ppt download template is suitable for sites with resources to sell vips one 2019-10-03 eight thousand seven hundred and sixty-nine 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 two thousand and seven hundred 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 forty-three thousand five hundred and ninety-two Price: two hundred and eighty-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
Cancel Reply welcome you Comment:
-
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 emlog three column We Media theme is applicable to We Media/Blog 03-21 -
two EMlog obtains the title link and other data of the specified classification through the classification ID 03-20 -
three Tianxing Studio zblog attachment management enhancement plug-in 03-17 -
four Tianxing Studio zblog Mall Template Mall Theme matches with member plug-in to realize online payment of shopping cart orders 03-13 -
five The reason and solution for the prompt No input file specified on the phpstudy 03-07 -
six Zblog gets the title/link/ID and other attributes of the current page 02-02 -
seven Notice of Tianxing Studio's 2023 Spring Festival Holiday 01-19 -
eight Windows+php studio+Apache set the method to allow cross domain requests 01-09 -
nine Troubleshooting method and solution for website using pagoda panel server CPU occupying 100% 01-04
-
Label aggregation -
× one Specify classification × one Website copyright × two Christmas × one Popular articles × three Zblog Taobao guest × one Dark color theme × one Zblogphp video theme × one Zblog charging template × one Js form validation × four Zblogcms template × one Publish video × three Install zblog × one Wap plug-in × one Website avatar × three seo × one Blog Theme × one robots.txt × three Zblog Theme Installation × one struggle × three Wordpress database
Latest comments
-
visitor 02-23 thank Commented on: Detailed description of zblog template article publishing time format -
one hundred and twenty-three 02-12 Hello, the test station cannot be opened when it is down, and cannot be accessed. -
visitor 01-07 It's the Spring Festival in 2023 Commented on: Notice of Tianxing Studio's 2022 Spring Festival Holiday -
visitor 12-01 Is there an old article time to update the plug-in Commented on: Detailed description of zblog template article publishing time format -
Swordsman Book 11-29 Too detailed, thanks for sharing! Commented on: Detailed description of zblog template article publishing time format