Skip to content

Instantly share code, notes, and snippets.

@alokstha1
Created March 19, 2015 06:42
Show Gist options
  • Save alokstha1/949d441110f5eb1df0fe to your computer and use it in GitHub Desktop.
Save alokstha1/949d441110f5eb1df0fe to your computer and use it in GitHub Desktop.
Pagination on archive.php, category.php, taxonomy.php on wordpress
<?php
if(have_posts()){
while ( have_posts() ) : the_post();
the_title();
endwhile;
}
previous_posts_link();
next_posts_link();
<?php
add_action('pre_get_posts', 'archive_paginations');
function archive_paginations($query){
if ( !is_admin() && $query->is_archive() && $query->is_main_query() ) {
global $wp_query;
$cat = $wp_query->get_queried_object();
$query->set( 'post_type', array( 'your_post_type', 'post' ) );
$query->set( 'posts_per_page', '4' );
$query->set( 'cat', $cat->slug );
}
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment