[WordPress]修改每頁顯示的文章數

ironman 2023-1-11 94

wp/includes/functions.php最後加入

function custom_posts_per_page($query){
    if(is_home()){
    $query->set('posts_per_page',10);//首頁每頁顯示10篇文章
    }
    if(is_search()){
        $query->set('posts_per_page',-1);//搜索頁顯示所有匹配的文章,不分頁
    }
    if(is_archive()){
        $query->set('posts_per_page',25);//archive每頁顯示25篇文章
}//endif
}//function
//this adds the function above to the 'pre_get_posts' action
add_action('pre_get_posts','custom_posts_per_page');

轉載自https://www.solagirl.net/wordpress-different-number-of-posts-per-page.html


i love you 3000
最新回復 (0)
返回
發新帖