• Hello all.
    First of all, I want to specify that I’m French, and my English is not very good. So excuse me in advance if I do some faults.

    I’m actually making a WordPress Theme, I’ve do the photoshop model and now I must do the code part. I use a static home page, so the template of my home page use the query for call all posts. But I’m trying to put the pagination after the posts.
    Here is the loop in my Home.php:

    <!-- BOUCLE -->
    	<?php
    	$query = new WP_query(array('post_type'=>'post'));
    	$query->query('category_name='.$catname.'&showposts=3'.'&paged='.$paged);
    	while($query->have_posts()): $query->the_post(); global $post;
    	?>
    
    	<div class="content">
    		<div class="post_title"><h1><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h1></div>
    		<div class="post_content"><?php global $more; $more = 0; the_content('Lire la suite'); ?></div>
    	</div>
    
    	<?php endwhile; ?> <!-- FIN BOUCLE -->
    	<div class="clear"></div>
    	<div class="navigation">
    		<?php next_posts_link('&laquo; Older Entries', $query->max_num_pages) ?>
    		<?php previous_posts_link('Newer Entries &raquo;') ?>
    	</div>

    The “Older Entries” link show up, and when I click it, he take me to the good link (https://myurl/page/numofthepage) but the page show the same posts. On all of pages I can only see the 3 firsts posts.
    How I can solve it ?
    Thank’s you in advance ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • “showposts” is deprecated, I think? Use “posts_per_page.”

    Also, I don’t think that you need “paged” — it should paginate by default if you use “posts_per_page.”

    Have not tested this, but what happens if you just do this?

    $args = array(
    	'posts_per_page'      => 3,
    	'category_name'       => $catname,
    );
    $query = new WP_Query( $args );

    this replaces your lines that say :

    $query = new WP_query(array('post_type'=>'post'));
    	$query->query('category_name='.$catname.'&showposts=3'.'&paged='.$paged);

    Oh, with a static page, it’s not so simple, I guess.

    Did a little research and turned up this …

    $paged = (get_query_var('page')) ? get_query_var('page') : 1;
    $args=array(
         'category_name'  => $catname,
         'posts_per_page'=>3,
         'paged'=>$paged);
    );
    $query = new WP_Query( $args );
    Thread Starter Yunir

    (@yunir)

    The second code is working fine ! Just, I had to delete the bracket and the semicolon (I’m not sure if I use the right words, sorry) after “‘paged’=>$paged” like that:

    $paged = (get_query_var('page')) ? get_query_var('page') : 1;
    	$args=array(
         'category_name'  => $catname,
         'posts_per_page'=>3,
         'paged'=>$paged
    	);
    	$query = new WP_Query( $args );

    Thank you so much !

    Oops, yes — typo. Great, glad it’s working!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Use the pagination with WP__query’ is closed to new replies.