PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 8, 2022

[FIXED] How can I set the limit number of the posts of a specify category into a page of that category?

 July 08, 2022     categories, limit, posts, wordpress     No comments   

Issue

I would to know how can I set the limit number of the posts visible into a page of a specify category.


Solution

Put this in your functions.php

function main_query_mods( $query ) {
    if(!$query->is_main_query()) {
        return;
    }
    // show 15 posts per page if category has id 7
    // check http://codex.wordpress.org/Conditional_Tags#A_Category_Page
    if ( is_category('7')) {
        $query->set('posts_per_page',15);
    }
}
add_action( 'pre_get_posts', 'main_query_mods' );


Answered By - offroff
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing