Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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++

    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 adiguba

    (@adiguba)

    Yes : it can be possible to do this on a theme, but I want to make an independant plugin, which would operate on all themes.

    In fact i’m using “WordPress MU”, and I want to make a plugin that would allow a blog to show posts from several other blogs.

    Even if this is not quite complete, I’am already do the job on the SQL query, by adding some filters (like ‘posts_query’ and ‘the_posts’).

    So my WordPress loop return to me differents posts from differents blogs, and each $post data includes an additional element “blog_ID”, allowing me to identify the blog.

    My problem is that I must call the switch_to_blog() with this “blog_ID”, before each post on the loop, in order to print correct data (permalink…) I’m doing this by adding a filter ‘loop_before_each’ at the end of the_post().

    But I think it could be interresting ta add the action directly on WordPress for futures versions (if I have this need, perhaps some others peoples can have the same).

    Thanks for replying,

    Bye

    Thread Starter adiguba

    (@adiguba)

    One mistake : the function have_post() can be called many time by a theme so it cannot déclare ‘loop_after_each’.

    But the action ‘loop_before_each’ on the_post() can be very useful for me…

    Bye

Viewing 4 replies - 1 through 4 (of 4 total)