• Hello,
    i am facing with huge problem. I created category.php with my own code. Everything is working fine except pagination for category.php . On all other pages same code works but not here, it gives on page/2/ 404 error.

    <?php
    
    $current_page = (get_query_var('paged')) ? get_query_var('paged') : 1; // get current page number
    $args = array(
      'posts_per_page' => 5, // the value from Settings > Reading by default
      'paged'          => $current_page // current page
    );
    query_posts( $args );
    
    $wp_query->is_archive = true;
    $wp_query->is_home = true;
    
    ?>
    
                         <div class="custom-pager">
                        <?php
                        if( function_exists('wp_pagenavi') ) wp_pagenavi(); // WP-PageNavi function
    
                        ?> <div class="clearfix"></div>
                          </div>
    
    <?php 
    
    while(have_posts()): the_post();
      ?>
    
                    <section class="vesti-box">
                      <div class="row">
                        <div class="col-md-5 col-sm-4">
                            <a href="<?php echo get_permalink(); ?>">
    
                            <span class="img-holder">
    
    <?php if ( get_field( 'naslovna_slika_vesti' ) ): ?>
                 <?php
                    $attachment_id = get_field('naslovna_slika_vesti');
                    $size = "newslistingImage"; // (thumbnail, medium, large, full or custom size)
                    $image2 = wp_get_attachment_image_src( $attachment_id, $size );
    
                  ?>
                   <img src="<?php echo $image2[0]; ?>" alt="Управа за аграрна пла?а?а " class="img-responsive">
    <?php else: ?>
    
                   <img src="<?php echo get_template_directory_uri(); ?>/img/bg/placeholder.jpg" alt="Управа за аграрна пла?а?а " class="img-responsive">
    <?php endif; ?>
    
                            </span></a>
                        </div>
                        <div class="col-md-7 col-sm-8 nopadding">
                            <h4><a href="<?php echo get_permalink(); ?>"><?php the_title(''); ?></a></h4>
                            <small><i class="fa fa-clock-o"></i> Об?ав?ено: <strong><?php the_time('j. F Y.') ?></strong></small>
                            <div class="news-txt">
                              <?php my_excerpt('bigshort');?>
                            </div>
                             <a href="<?php echo get_permalink(); ?>" class="detailed-red">Дета?ни?е</a>
                        </div>
                      </div>
                    </section>
    
                        <?php
                        endwhile;
                        ?>
    
                         <div class="custom-pager">
                        <?php
                        if( function_exists('wp_pagenavi') ) wp_pagenavi(); // WP-PageNavi function
    
                        ?>
                          </div>
    
                  </div>
Viewing 1 replies (of 1 total)
  • Is there any reason you’re trying to modify the query? If so, you should probably use new WP_Query instead query_posts(). In anycase, below is some untested code that may work.

    <?php if ( function_exists( 'wp_pagenavi' ) ) : ?>
    	<div class="custom-pager">
    		<?php wp_pagenavi(); ?>
    		<div class="clearfix"></div>
    	</div>
    <?php endif; ?>
    
    <?php while( have_posts() ) : the_post(); ?>
    
    	<section class="vesti-box">
    
    		<div class="row">
    
    			<div class="col-md-5 col-sm-4">
    				<a href="<?php the_permalink(); ?>">
    					<span class="img-holder">
    						<?php
    						$image         = get_template_directory_uri() . '/img/bg/placeholder.jpg';
    						$attachment_id = get_field( 'naslovna_slika_vesti' );
    
    						if ( ! empty( $attachment_id ) ) {
    							$image = wp_get_attachment_image_src( absint( $attachment_id ), 'newslistingImage' );
    							$image = $image[0];
    						}
    						?>
    
    						<img src="<?php echo esc_url( $image ); ?>" alt="Управа за аграрна пла?а?а" class="img-responsive">
    
    					</span>
    				</a>
    			</div>
    
    			<div class="col-md-7 col-sm-8 nopadding">
    				<?php the_title( '<h4><a href="' . esc_url( get_permalink() ) . '">', '</a></h4>' ); ?>
    				<small><i class="fa fa-clock-o"></i> Об?ав?ено: <strong><?php the_time( 'j. F Y.' ); ?></strong></small>
    				<div class="news-txt">
    					<?php my_excerpt( 'bigshort' );?>
    				</div>
    				 <a href="<?php the_permalink(); ?>" class="detailed-red">Дета?ни?е</a>
    			</div>
    
    		</div>
    
    	</section>
    
    <?php endwhile; ?>
    
    <?php if ( function_exists( 'wp_pagenavi' ) ) : ?>
    	<div class="custom-pager">
    		<?php wp_pagenavi(); ?>
    	</div>
    <?php endif; ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Category page and pagination’ is closed to new replies.