wordpress怎麼實現不同分類調用不同的文章數?

來源:互聯網
上載者:User
有三個分類(category): 新聞產品(產品子分類1,產品子分類2,產品子分類3), 協助
要求實現:
新聞分類頁顯示10條新聞後分頁,產品與產品子分類頁顯示5條產品後分頁,協助分類頁顯示20條協助列表後分頁。

回複內容:

有三個分類(category):新聞產品(產品子分類1,產品子分類2,產品子分類3),協助
要求實現:
新聞分類頁顯示10條新聞後分頁,產品與產品子分類頁顯示5條產品後分頁,協助分類頁顯示20條協助列表後分頁。

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');
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.