wordpress
发布时间:2022-05-06 发布网站:大佬教程 code.js-code.com
大佬教程收集整理的这篇文章主要介绍了WordPress中自定义不同分类页面每页显示条数,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
前面的教程中,我们已经介绍了的方法。站长朋友们在使用的过程中,通常还需要自定义不同分类页面每页显示条数。比如新闻分类页面我们希望每页显示10条新闻,而产品分类页面,我们希望每页显示9个产品。这篇教程里,我们就向大家介绍一下方法。
切换到主题目录,打开functions.PHP文件,加入以下代码:
Crayon-5c891ce0c3aef113607351" class="
Crayon-
Syntax Crayon-theme-classic
Crayon-font-monaco
Crayon-os-pc print-yes notranslate" data-set
Tings=" minimize scroll-mou
SEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-set
Tings=" mou
SEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-@R_674_10283@e">functions.PHPCrayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button
Crayon-nums-button" @R_
674_10283@e="Toggle Line
numbers">
Crayon-button-icon">
Crayon-button
Crayon-plain-button" @R_
674_10283@e="Toggle Plain Code">
Crayon-button-icon">
Crayon-button
Crayon-wrap-button" @R_
674_10283@e="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button
Crayon-expand-button" @R_
674_10283@e="Expand Code">
Crayon-button-icon">
Crayon-button
Crayon-copy-button" @R_
674_10283@e="Copy">
Crayon-button-icon">
Crayon-button
Crayon-popup-button" @R_
674_10283@e="Open Code In New Window">
Crayon-button-icon">
Crayon-language">PHP@H_
607_37@set('posts_per_page',
9);
}
}
add_action( 'pre_get_posts','main_query_mods'
);Crayon-main" style="">
Crayon-table">Crayon-row">Crayon-nums " data-setTings="show">Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;"> Crayon-num" data-line=" Crayon-5c891ce0c3aef113 607351-1">1 Crayon-num" data-line=" Crayon-5c891ce0c3aef113 607351-3">3 Crayon-num" data-line=" Crayon-5c891ce0c3aef113 607351-5">5 Crayon-num" data-line=" Crayon-5c891ce0c3aef113 607351-7">7 Crayon-num" data-line=" Crayon-5c891ce0c3aef113 607351-9">9 | Crayon-code">Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size :4; -o-tab-size :4; -webkit-tab-size :4; tab-size :4;"> Crayon-line" id=" Crayon-5c891ce0c3aef113 607351-1"> Crayon-t">functionCrayon-h"> Crayon-e">main_query_modsCrayon-sy">(Crayon-h"> Crayon-v">$queryCrayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-line Crayon- Striped-line" id=" Crayon-5c891ce0c3aef113 607351-2"> Crayon-h">Crayon-st">ifCrayon-sy">(Crayon-o">!Crayon-v">$queryCrayon-e">is_main_queryCrayon-sy">(Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-line" id=" Crayon-5c891ce0c3aef113 607351-3"> Crayon-h">Crayon-k ">returnCrayon-sy">;Crayon-line" id=" Crayon-5c891ce0c3aef113 607351-5"> Crayon-h">Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">is_categoryCrayon-sy">(Crayon-s">'分类目录的ID'Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-sy">{Crayon-line Crayon- Striped-line" id=" Crayon-5c891ce0c3aef113 607351-6"> Crayon-h">Crayon-v">$queryCrayon-e">setCrayon-sy">(Crayon-s">'posts_per_page'Crayon-sy">,Crayon-cn">9Crayon-sy">)Crayon-sy">;Crayon-line" id=" Crayon-5c891ce0c3aef113 607351-7"> Crayon-h">Crayon-sy">}Crayon-line" id=" Crayon-5c891ce0c3aef113 607351-9"> Crayon-e">add_actionCrayon-sy">(Crayon-h"> Crayon-s">'pre_get_posts'Crayon-sy">,Crayon-h"> Crayon-s">'main_query_mods'Crayon-h"> Crayon-sy">)Crayon-sy">; |
@H_41_197@大佬总结
以上是大佬教程为你收集整理的WordPress中自定义不同分类页面每页显示条数全部内容,希望文章能够帮你解决WordPress中自定义不同分类页面每页显示条数所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。