Home > Backend Development > PHP Tutorial > wordpress怎么实现不同分类调用不同的文章数?

wordpress怎么实现不同分类调用不同的文章数?

WBOY
Release: 2016-06-06 20:22:21
Original
1423 people have browsed it

有三个分类(category):新闻产品(产品子分类1,产品子分类2,产品子分类3),帮助
要求实现:
新闻分类页显示10条新闻后分页,产品与产品子分类页显示5条产品后分页,帮助分类页显示20条帮助列表后分页。

回复内容:

有三个分类(category):新闻产品(产品子分类1,产品子分类2,产品子分类3),帮助
要求实现:
新闻分类页显示10条新闻后分页,产品与产品子分类页显示5条产品后分页,帮助分类页显示20条帮助列表后分页。

<code>function filter_pre_get_posts( $query ){
  if ( $query->is_main_query() ){
    $num = '';
    if ( is_category(array('questions')) ){ $num = 14; }
    if ( is_category(array(9)) ){ $num = 14; }
    if ( is_category(array(10)) ){ $num = 14; }
    if ( is_category(array(11)) ){ $num = 14; }
    if ( is_category(array(12)) ){ $num = 14; }
    if ( is_category(array(13)) ){ $num = 14; }
    // if ( in_category(array('jhg','hjj','yjj','xxj','jlg')) ){ $num = 10; }
    //if ( is_home() ){ $num = 10; }
    // else if ( is_category() ){ $num = 10; }
    // else if ( is_tag() ){ $num = 10; }
    // else if ( is_date() ){ $num = 10; }
    // else if ( is_author() ){ $num = 10; }
    // else if ( is_search() ){ $num = 10; }
    // else if ( is_archive() ){ $num = 10; }
    if ( '' != $num ){ $query->set( 'posts_per_page', $num ); }
  }
  return $query;
}
add_action('pre_get_posts', 'filter_pre_get_posts');</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template