• Hi everyone (sorry i f my english is bad but i’m a french guy ?? )
    So my problem is the next:

    I bought a template 2weeks ago. The code below:

    <div id="column-setup"><!-- Begin Column Setup -->
    	<div class="column-left"><!-- Begin Post One Block -->
    	<?php $my_query = new WP_Query('showposts=1&offset=0'); ?>
    	<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    		<h1 class="block-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    		<h5 class="postinfo"><?php the_time('F j, Y'); ?> &nbsp;&nbsp; // &nbsp;&nbsp; Par <?php the_author(); ?></h5>
    		<a href="<?php the_permalink(); ?>"><img src="<?php viva(70,'');?>" alt="<?php the_title(); ?> <?php _e('thumbnail'); ?>" align="left" style="border: 1px solid #b4b4b4; padding: 1px; margin: 2px 20px 0px 0px; width: 70px; height: 70px;"/></a>
    		<?php wswwpx_content_extract ( ' ', 18, 18 ); ?><br /><br />
    		<p align="right"><a href="<?php the_permalink(); ?>">Lire la suite</a></p>
    	<?php endwhile; ?>
    	</div><!-- End Post One Block -->
    	<div class="column-middle"><!-- Begin Post Two Block -->
    	<?php $my_query = new WP_Query('showposts=1&offset=1'); ?>
    	<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    		<h1 class="block-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    		<h5 class="postinfo"><?php the_time('F j, Y'); ?> &nbsp;&nbsp; // &nbsp;&nbsp; Par <?php the_author(); ?></h5>
    		<a href="<?php the_permalink(); ?>"><img src="<?php viva(70,'');?>" alt="<?php the_title(); ?> <?php _e('thumbnail'); ?>" align="left" style="border: 1px solid #b4b4b4; padding: 1px; margin: 2px 20px 0px 0px; width: 70px; height: 70px;"/></a>
    		<?php wswwpx_content_extract ( ' ', 18, 18 ); ?><br /><br />
    		<p align="right"><a href="<?php the_permalink(); ?>">Lire la suite</a></p>
    	<?php endwhile; ?>
    	</div><!-- End Post Two Block -->
    	<div class="column-right"><!-- Begin Post Three Block -->
    	<?php $my_query = new WP_Query('showposts=1&offset=2'); ?>
    	<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    		<h1 class="block-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    		<h5 class="postinfo"><?php the_time('F j, Y'); ?> &nbsp;&nbsp; // &nbsp;&nbsp; Par <?php the_author(); ?></h5>
    		<a href="<?php the_permalink(); ?>"><img src="<?php viva(70,'');?>" alt="<?php the_title(); ?> <?php _e('thumbnail'); ?>" align="left" style="border: 1px solid #b4b4b4; padding: 1px; margin: 2px 20px 0px 0px; width: 70px; height: 70px;"/></a>
    		<?php wswwpx_content_extract ( ' ', 18, 18 ); ?><br /><br />
    		<p align="right"><a href="<?php the_permalink(); ?>">Lire la suite</a></p>
    	<?php endwhile; ?>
    	</div><!-- End Post Three Block -->
    	<div style="clear: both;border-bottom: 1px solid #e9e9e9;"></div>
    	<div class="column-left"><!-- Begin Post Four Block -->
    	<?php $my_query = new WP_Query('showposts=1&offset=3'); ?>
    	<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    		<h1 class="block-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    		<h5 class="postinfo"><?php the_time('F j, Y'); ?> &nbsp;&nbsp; // &nbsp;&nbsp; Par <?php the_author(); ?></h5>
    		<a href="<?php the_permalink(); ?>"><img src="<?php viva(70,'');?>" alt="<?php the_title(); ?> <?php _e('thumbnail'); ?>" align="left" style="border: 1px solid #b4b4b4; padding: 1px; margin: 2px 20px 0px 0px; width: 70px; height: 70px;"/></a>
    		<?php wswwpx_content_extract ( ' ', 18, 18 ); ?><br /><br />
    		<p align="right"><a href="<?php the_permalink(); ?>">Lire la suite</a></p>
    	<?php endwhile; ?>
    	</div><!-- End Post Four Block -->
    	<div class="column-middle"><!-- Begin Post Five Block -->
    	<?php $my_query = new WP_Query('showposts=1&offset=4'); ?>
    	<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    		<h1 class="block-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    		<h5 class="postinfo"><?php the_time('F j, Y'); ?> &nbsp;&nbsp; // &nbsp;&nbsp; Par <?php the_author(); ?></h5>
    		<a href="<?php the_permalink(); ?>"><img src="<?php viva(70,'');?>" alt="<?php the_title(); ?> <?php _e('thumbnail'); ?>" align="left" style="border: 1px solid #b4b4b4; padding: 1px; margin: 2px 20px 0px 0px; width: 70px; height: 70px;"/></a>
    		<?php wswwpx_content_extract ( ' ', 18, 18 ); ?><br /><br />
    		<p align="right"><a href="<?php the_permalink(); ?>">Lire la suite</a></p>
    	<?php endwhile; ?>
    	</div><!-- End Post Five Block -->
    	<div class="column-right"><!-- Begin Post Six Block -->
    	<?php $my_query = new WP_Query('showposts=1&offset=5'); ?>
    	<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    		<h1 class="block-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    		<h5 class="postinfo"><?php the_time('F j, Y'); ?> &nbsp;&nbsp; // &nbsp;&nbsp; Par <?php the_author(); ?></h5>
    		<a href="<?php the_permalink(); ?>"><img src="<?php viva(70,'');?>" alt="<?php the_title(); ?> <?php _e('thumbnail'); ?>" align="left" style="border: 1px solid #b4b4b4; padding: 1px; margin: 2px 20px 0px 0px; width: 70px; height: 70px;"/></a>
    		<?php wswwpx_content_extract ( ' ', 18, 18 ); ?><br /><br />
    		<p align="right"><a href="<?php the_permalink(); ?>">Lire la suite</a></p>
    	<?php endwhile; ?>
    	</div><!-- End Post Six Block -->
    	<div style="clear: both;border-bottom: 1px solid #e9e9e9;"></div>
    	<div class="column-left"><!-- Begin Post Seven Block -->
    	<?php $my_query = new WP_Query('showposts=1&offset=6'); ?>
    	<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    		<h1 class="block-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    		<h5 class="postinfo"><?php the_time('F j, Y'); ?> &nbsp;&nbsp; // &nbsp;&nbsp; Par <?php the_author(); ?></h5>
    		<a href="<?php the_permalink(); ?>"><img src="<?php viva(70,'');?>" alt="<?php the_title(); ?> <?php _e('thumbnail'); ?>" align="left" style="border: 1px solid #b4b4b4; padding: 1px; margin: 2px 20px 0px 0px; width: 70px; height: 70px;"/></a>
    		<?php wswwpx_content_extract ( ' ', 18, 18 ); ?><br /><br />
    		<p align="right"><a href="<?php the_permalink(); ?>">Lire la suite</a></p>
    	<?php endwhile; ?>
    	</div><!-- End Post Seven Block -->
    	<div class="column-middle"><!-- Begin Post Eight Block -->
    	<?php $my_query = new WP_Query('showposts=1&offset=7'); ?>
    	<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    		<h1 class="block-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    		<h5 class="postinfo"><?php the_time('F j, Y'); ?> &nbsp;&nbsp; // &nbsp;&nbsp; Par <?php the_author(); ?></h5>
    		<a href="<?php the_permalink(); ?>"><img src="<?php viva(70,'');?>" alt="<?php the_title(); ?> <?php _e('thumbnail'); ?>" align="left" style="border: 1px solid #b4b4b4; padding: 1px; margin: 2px 20px 0px 0px; width: 70px; height: 70px;"/></a>
    		<?php wswwpx_content_extract ( ' ', 18, 18 ); ?><br /><br />
    		<p align="right"><a href="<?php the_permalink(); ?>">Lire la suite</a></p>
    	<?php endwhile; ?>
    	</div><!-- End Post Eight Block -->
    	<div class="column-right"><!-- Begin Post Nine Block -->
    	<?php $my_query = new WP_Query('showposts=1&offset=8'); ?>
    	<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    		<h1 class="block-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    		<h5 class="postinfo"><?php the_time('F j, Y'); ?> &nbsp;&nbsp; // &nbsp;&nbsp; Par <?php the_author(); ?></h5>
    		<a href="<?php the_permalink(); ?>"><img src="<?php viva(70,'');?>" alt="<?php the_title(); ?> <?php _e('thumbnail'); ?>" align="left" style="border: 1px solid #b4b4b4; padding: 1px; margin: 2px 20px 0px 0px; width: 70px; height: 70px;"/></a>
    		<?php wswwpx_content_extract ( ' ', 18, 18 ); ?><br /><br />
    		<p align="right"><a href="<?php the_permalink(); ?>">Lire la suite</a></p>
    	<?php endwhile; ?>
    	</div><!-- End Post Nine Block -->
    </div><!-- End Column Setup -->

    It is a square presentation: 3 with 3 line items.
    The problem is that I have no paging my pages so I can see that the last 9 items.

    How do I make a pagination with wp_query ()?

    I see a lot of post with paged but i don’t understand how i must integrate the code.

    Can you help me ?

    Thank you in advance for your help

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter batoust

    (@batoust)

    If you want to see the website: https://www.itest-app.fr

    Thread Starter batoust

    (@batoust)

    nobody can help me (don’t worry for the code, it’s a repeat of 9 posts)

    Salut,

    Joli design ??

    Ton problème vient du fait que tu génères 9 “query” qui n’ont aucun lien avec la requête principale de WordPress. Donc aucune pagination ni rien… sans compter la grosse duplication du code !

    Il serait préférable d’utiliser la boucle principale de WordPress, en utilisant un compteur pour générer le bon nom de classe :

    <?php if (have_posts()) : ?>
    
    <?php
    	// Le style de tes différents blocs :
    	$columns = array('left', 'middle', 'right');
    	// Le compteur de bloc :
    	$columnIndex = 0;
    ?>
    
    <div id="column-setup"><!-- Begin Column Setup -->
    
    	<?php while (have_posts()) : the_post(); ?>
    
    		<div class="column-<?php echo $columns[$columnIndex]; ?>"><!-- Begin Post -->
    
    			<h1 class="block-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    			etc...
    			<p align="right"><a href="<?php the_permalink(); ?>">Lire la suite</a></p>
    
    		</div><!-- End Post -->
    
    		<?php $columnIndex++; ?>
    		<?php if ($columnIndex==count($column)) : $columnIndex = 0; ?>
    		<div style="clear: both;border-bottom: 1px solid #e9e9e9;"></div>
    		<?php endif; ?>
    
    	<?php endwhile; ?>
    
    	<div class="navigation">
    		<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    		<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    	</div>
    
    </div><!-- End Column Setup -->
    
    <?php else : ?>
    	... no post ...
    <?php endif; ?>

    Ensuite il suffit d’aller dans les options de ton blog “Réglages -> Lecture” et d’indiquer que tu veux afficher 9 pages à la fois au lieu de 10…

    Je n’ai pas testé mais ca devrait marcher…

    a++

    Thread Starter batoust

    (@batoust)

    Merci pour ton aide, je vais tester tout ca et je te dirais ce que ca donne ??

    Thread Starter batoust

    (@batoust)

    HS – Alors il me fait bien la pagination, mais par contre il n’affiche que les trois premiers articles en bloc, les autres sont en liste :s – HS

    Pour voir le résultat: https://www.itest-app.fr

    J’ai rectifié l’erreur en mettant dans la condition if si l’indexcolumn est égale a 3 alors on repart à 0.

    Par contre mon site me semble plus lent, impression ou est ce que c’est pcq le code a changer ?

    En effet il y avait une erreur de frappe dans mon code : il manquait un ‘s’ ) columns sur cette ligne :
    <?php if ($columnIndex==count($columns)) : $columnIndex = 0; ?>

    Par contre je ne pense pas que cela pose un problème de lenteur. C’est une boucle des plus standards et surtout, tu as une seule requête SQL au lieu de 9 précédemment…

    a++

    Thread Starter batoust

    (@batoust)

    Oui c’était mon hébergeur qui ralentissait un peu.

    En tout cas merci de ton aide c’est super sympa ??

    a++

    <?php if ($columnIndex==count($column)) : $columnIndex = 0; ?>

    TRUE:

    <?php if ($columnIndex==count($columns)) : $columnIndex = 0; ?>

    ITS WORK

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Pagination with WP_Query()’ is closed to new replies.