Hi everyone I’m trying to make pagination in custom template page for custom post type. When I click Older entries
it redirects me to localhost/videos/page/2/
which is ok but it displays index.php content not videos.php. Here is my videos.php:
<?php
/*Template name: Videos*/
get_header(); ?>
<div class="wrapper">
<div class="row home-row slider-box" id="sliders">
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
// The Query
$the_query = new WP_Query( array(
'post_status'=>'publish',
'post_type' => 'videos',
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page' => '1',
'paged'=>$paged ) );
$count = 1;
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
get_template_part('content', 'videos');
endwhile;
next_posts_link( 'Older Entries', $the_query->max_num_pages );
previous_posts_link( 'Newer Entries' );
?>
</div>
And here is how my functions looks:
function videos(){
$args = array(
'public' => true,
'label' => __('Videos'),
'rewrite' => array('slug' => 'videos', 'with_front' => true),
'supports' => array('title', 'editor', 'thumbnail'));
register_post_type('videos', $args);
register_taxonomy('videos', 'nagrody');
}
add_action('init', 'videos');
Why this pagination doesn’t work properly?
WordPress pagination works on the main query. So on this page the pagination would work on the
page
not theWP_Query
you have added since the main query will be to get the videos page.If you set
has_archive
to true when creating yourvideos
post type you can create an archive page for it underarchive-videos.php
and use that to display the posts, and pagination will work.You may be able to fix it without the archive page, try reading here https://wordpress.stackexchange.com/questions/120407/how-to-fix-pagination-for-custom-loops