Custom query pagination in category template.
-
Hi everyone!
It’s my first post.
I have problem with pagination.
My code for category.php is:<?php get_header(); ?> <?php if(!(in_category(array(15,16)))):?> <?php $paged = ( isset( $_GET['pg'] ) && intval( $_GET['pg'] ) > 0 )? intval( $_GET['pg'] ) : 1; query_posts( array( 'post_type' => 'post', 'paged' => $paged, 'posts_per_page' => -1 ) );?> <?php if ( have_posts() ) : ?> <?php if (is_sticky()): ?> <section id="slider"> <?php $category = get_the_category($post->ID); $category = $category[0]->cat_ID;?> <?php $args = array( 'post__in' => get_option( 'sticky_posts' ), 'paged' => $paged, ); $the_query = new WP_Query( $args ); while ($the_query -> have_posts()) : $the_query -> the_post(); ?> <?php if ( in_category($category)): ?> <?php get_template_part( 'slider' ); ?> <?php endif; ?> <?php endwhile;?> <?php wp_reset_postdata(); ?> </section> <?php endif ?> <?php endif;?> <?php if ( have_posts() ) : ?> <div id="tabs"> <ul class="nav nav-tabs"> <li class="active"><a href="#news" data-toggle="tab"><?php _e('Nejnovější','trvale')?></a></li> <li><a href="#recent" data-toggle="tab"><?php _e('Nejčtenější','trvale')?></a></li> </ul> <div class="tab-content"> <div class="tab-pane active" id="news"> <?php //Recently Post From Same Category ?> <?php $category = get_the_category($post->ID); $category = $category[0]->cat_ID; $recentpost = new WP_Query( array( 'posts_per_page' => -1, 'paged' => $paged, 'order' => 'ASC','posts_per_page' => 3, 'category__in' => $category) ); while ( $recentpost->have_posts() ) : $recentpost->the_post(); ?> <article class="<?php foreach(get_the_category() as $category) {echo $category->slug . ' ';} ?> box post"> <div class="desc"> <h2><a href="<?php the_permalink()?>"><?php the_title();?></a></h2> <p><?php echo excerpt(25); ?></p> </div> <div class="photo"> <?php if (has_post_thumbnail()):?> <?php echo get_the_post_thumbnail( get_the_ID(), 'article', array('class' => 'img-responsive')); ?> <?php else: ?> <img data-src="holder.js/331x156" class="img-responsive"> <?php endif; ?> </div> <ul class="info"> <li><a href="<?php the_permalink()?>" class="btn btn-more"><?php _e('Celý článek','trvale')?></a></li> <li class="type"></li> <li class="share"><div class="fb-share-button social" data-href="<?php the_permalink() ?>" data-type="button_count"></div></li> <li class="counter"><?php echo getPostViews(get_the_ID());?> ×</li> </ul> </article> <?php endwhile; ?> <?php wp_reset_query(); ?> </div> <div class="tab-pane" id="recent"> <?php $category = get_the_category($post->ID); $category = $category[0]->cat_ID; $popularpost = new WP_Query( array( 'posts_per_page' => 2, 'meta_key' => 'wpb_post_views_count', 'paged' => $paged, 'orderby' => 'meta_value_num', 'order' => 'ASC', 'category__in' => $category) ); while ( $popularpost->have_posts() ) : $popularpost->the_post(); ?> <?php if ( in_category($category)): ?> <article class="<?php foreach(get_the_category() as $category) {echo $category->slug . ' ';} ?> box post"> <div class="desc"> <h2><a href="<?php the_permalink()?>"><?php the_title();?></a></h2> <p><?php echo excerpt(25); ?></p> </div> <div class="photo"> <?php if (has_post_thumbnail()):?> <?php echo get_the_post_thumbnail( get_the_ID(), 'article', array('class' => 'img-responsive')); ?> <?php else: ?> <img data-src="holder.js/331x156" class="img-responsive"> <?php endif; ?> </div> <ul class="info"> <li><a href="<?php the_permalink()?>" class="btn btn-more"><?php _e('Celý článek','trvale')?></a></li> <li class="type"></li> <li class="share"><div class="fb-share-button social" data-href="<?php the_permalink() ?>" data-type="button_count"></div></li> <li class="counter"><?php echo getPostViews(get_the_ID());?> ×</li> </ul> </article> <?php endif; ?> <?php endwhile; ?> </div> </div> </div> <?php endif; ?> <?php else: ?> <?php if ( have_posts() ) : ?> <div class="box posts"> <header> <h1><?php printf( __( '%s', 'trvale' ), single_tag_title( '', false ) ); ?></h1> <div class="fb-share-button social" data-href="<?php the_permalink() ?>" data-type="button_count"></div> <?php if (tag_description()): ?> <p><?php echo tag_description(); ?></p> <?php endif; ?> </header> <?php while ( have_posts() ) : the_post(); ?> <article> <h2><?php the_title();?></h2> <?php the_content();?> </article> <?php endwhile; ?> </div> <?php endif; ?> <?php endif; ?> <?php get_footer()?>How to get pagination in recent tab-pane?
Thank you for any suggestions.
The topic ‘Custom query pagination in category template.’ is closed to new replies.