Created
March 19, 2015 06:42
-
-
Save alokstha1/949d441110f5eb1df0fe to your computer and use it in GitHub Desktop.
Pagination on archive.php, category.php, taxonomy.php on wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(have_posts()){ | |
while ( have_posts() ) : the_post(); | |
the_title(); | |
endwhile; | |
} | |
previous_posts_link(); | |
next_posts_link(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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