Advertisement
pusatdata

Mengatur Jumlah Post per Kategori

Jun 1st, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. Sumber:
  2. https://www.webhostinghero.com/change-the-number-of-posts-category-wordpress/
  3.  
  4. functions.php:
  5.  
  6. MODEL-1:
  7. add_filter('pre_get_posts', 'posts_in_category');
  8. function posts_in_category($query){
  9. if ($query->is_category) {
  10. if (is_category('book-reviews')) {
  11. $query->set('posts_per_archive_page', 2);
  12. }
  13. // category With ID = 32 show only 5 posts
  14. if (is_category('politics')){
  15. $query->set('posts_per_archive_page', 1);
  16. }
  17. }
  18. }
  19.  
  20. atau contoh lainnya
  21.  
  22.  
  23.  
  24. add_filter('pre_get_posts', 'posts_in_category');
  25. function posts_in_category($query){
  26. if ($query->is_category) {
  27. if (is_category('19')) {
  28. $query->set('posts_per_archive_page', 50);
  29. }
  30. // category With ID = 32 show only 5 posts
  31. if (is_category('20')){
  32. $query->set('posts_per_archive_page', 50);
  33. }
  34. if (is_category('21')){
  35. $query->set('posts_per_archive_page', 50);
  36. }
  37. if (is_category('profil-kecamatan')){
  38. $query->set('posts_per_archive_page', 20);
  39. }
  40. if (is_category('profil-kelurahan')){
  41. $query->set('posts_per_archive_page', 20);
  42. }
  43. }
  44. }
  45.  
  46.  
  47. MODEL-2:
  48. function hwl_home_pagesize( $query )
  49. {
  50. if ( is_category( 9 ) )
  51. {
  52. // If you want "posts per page"
  53. $query->query_vars['posts_per_page'] = 1;
  54. return;
  55. }
  56. if ( is_category( 'movie' ) )
  57. {
  58. // If you want "showposts"
  59. $query->query_vars['showposts'] = 50;
  60. return;
  61. }
  62. }
  63. add_action( 'pre_get_posts', 'hwl_home_pagesize', 1 );
  64.  
  65. Menggunakan Plugin "Posts Per Category":
  66. http://wordpress.org/plugins/posts-per-category/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement