Quantcast
Channel: User Michael - WordPress Development Stack Exchange
Viewing all articles
Browse latest Browse all 44

Answer by Michael for How to add page numbering with php?

$
0
0

to change the number of 'posts_per_page' for one specific category archive page (assuming your are using a different number for all other archives), try working with the 'pre_get_posts' action; see https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

assuming that your category template is for the 'video' category, the code to be added into functions.php of your (child) theme, could be, for example:

function video_category_pagesize( $query ) {    if ( is_admin() || ! $query->is_main_query() )        return;    if ( is_category( 'video' ) ) {        // Display 5 posts per page for the 'video' category archive        $query->set( 'posts_per_page', 5 );        return;    }}add_action( 'pre_get_posts', 'video_category_pagesize' );

for the next prev buttons, for example, consider to use https://codex.wordpress.org/Function_Reference/next_posts_link and https://codex.wordpress.org/Function_Reference/previous_posts_linkand review https://codex.wordpress.org/Pagination


Viewing all articles
Browse latest Browse all 44

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>