• Resolved Malcom24

    (@malcom24)


    Hello,

    Before anything, I have spent the past 3 hours browsing forums and trying to apply the solutions I found to my problem, but I just can’t get it to work.

    I created a custom page template, I used the Page Navi plugin to get a custom pagination, but page 2 always returns a 404 error… frustrating.

    Here is my page code :

    <?php
    
     $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
    
     $args = array(
    'category_name'=>"actualiteprincipale",
    'posts_per_page' => 1,
    'paged' => $paged
    );
    
    // Pagination fix
    $temp_query = $wp_query;
    $wp_query   = NULL;
    $wp_query = new WP_Query();
    $wp_query->query($args);
    
    if ( $wp_query->have_posts() ) :
    	while ( $wp_query->have_posts() ) :
    	 $wp_query->the_post();  // Si pas vide
    
    	 $url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 5600,1000 ), false, '' ); // On récupère l'image pour l'insérer après
    ?>
    
    <div class="mainactublock" style="background-image: url('<?php echo $url[0]; ?>')">
     <div class="whiteborder">
      <h2 class="mainactutitle"> <?php the_title(); ?> </h2>
     </div>
    </div>
    
      <div class="mainactudesc">
    	<div class="row actupart">
    	  <div class="col-md-12 col-xs-12">
    	    <p class="mainactudate">Posté le <?php the_date(); ?>, il y a  <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . '.';?></p>
                 </div>
    	</div>
    	<div class="row">
    
    	<div class="col-md-7 col-xs-12 excerpt">
    	  <?php the_excerpt(); ?>
    	</div>
    
           <div class="col-md-5 col-xs-12">
    	  <a class="mainactulink" href="<?php the_permalink() ?>" title="En savoir plus">En savoir plus</a>
    	</div>
        </div>
    </div>
    
    <?php endwhile;
    endif;
    	wp_reset_postdata();
    	// Custom query loop pagination
    	wp_pagenavi();
    
            // Reset main query object
    	$wp_query = NULL;
    	$wp_query = $temp_query;
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Malcom24

    (@malcom24)

    Any idea would be appreciated, I’ve tried lots of solutions.

    Thread Starter Malcom24

    (@malcom24)

    Whatever, I found the solution. My custom template was a “category-name” template, after I changed to a “page-name” template it worked.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom template second page returning 404’ is closed to new replies.