Je relance sur le Hub un thread que j'avais lancé sur le support WP Francophone car je n'ai pas résolu mon problème
Sur l'accueil de Adicie.com , j'affiche les derniers billets parus, ainsi que chaque dernier billet par catégorie.
Du coup, je me retrouve avec des doublons que je voudrais éradiquer.
Le but serait de fabriquer une boucle qui indiquerait que si un billet est paru dans "derniers articles parus", il ne doit pas s'afficher ailleurs.
Au départ, mon code est :
- Pour les derniers articles parus :
CODE
1.
<?php _e('Derniers articles parus'); ?></h3>
2.
<?php query_posts('showposts=3'); ?>
3.
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
4.
<?php the_date('j F Y') ?> par <?php the_author() ?> <br />
5.
<a href="<?php the_permalink(); ?>" title="<?php the_title() ?>" class="title"><?php the_title() ?></a>
6.
<?php the_excerpt(); ?>
7.
[ <a href="<?php the_permalink() ?>" rel="bookmark" title="Lien permanent vers <?php the_title(); ?>">Lire la suite</a> ]<br /><br />
8.
<?php endwhile; endif; ?>
<?php _e('Derniers articles parus'); ?></h3>
2.
<?php query_posts('showposts=3'); ?>
3.
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
4.
<?php the_date('j F Y') ?> par <?php the_author() ?> <br />
5.
<a href="<?php the_permalink(); ?>" title="<?php the_title() ?>" class="title"><?php the_title() ?></a>
6.
<?php the_excerpt(); ?>
7.
[ <a href="<?php the_permalink() ?>" rel="bookmark" title="Lien permanent vers <?php the_title(); ?>">Lire la suite</a> ]<br /><br />
8.
<?php endwhile; endif; ?>
- Pour les derniers billets dans leur catégorie :
CODE
1.
<?php
2.
// this is where the Politique module begins
3.
query_posts('showposts=2&cat=10'); ?>
4.
<h3><?php
5.
// this is where the name of the Politique category gets printed
6.
wp_list_categories('include=10&title_li=&style=none'); ?></h3>
7.
<?php while (have_posts()) : the_post(); ?>
8.
<div class="feature"><a href="<?php the_permalink() ?>" rel="bookmark" title="Lien permanent vers <?php the_title(); ?>"></a><a href="<?php the_permalink() ?>" rel="bookmark" class="title">
9.
<?php
10.
// this is where title of the Politique gets printed
11.
the_title(); ?></a>
12.
<?php
13.
// this is where the excerpt of the Politique gets printed
14.
the_excerpt(); ?>
15.
[ <a href="<?php the_permalink() ?>" rel="bookmark" title="Lien permanent vers <?php the_title(); ?>">Lire la suite</a> ]
16.
</div>
17.
<?php endwhile; ?>
<?php
2.
// this is where the Politique module begins
3.
query_posts('showposts=2&cat=10'); ?>
4.
<h3><?php
5.
// this is where the name of the Politique category gets printed
6.
wp_list_categories('include=10&title_li=&style=none'); ?></h3>
7.
<?php while (have_posts()) : the_post(); ?>
8.
<div class="feature"><a href="<?php the_permalink() ?>" rel="bookmark" title="Lien permanent vers <?php the_title(); ?>"></a><a href="<?php the_permalink() ?>" rel="bookmark" class="title">
9.
<?php
10.
// this is where title of the Politique gets printed
11.
the_title(); ?></a>
12.
<?php
13.
// this is where the excerpt of the Politique gets printed
14.
the_excerpt(); ?>
15.
[ <a href="<?php the_permalink() ?>" rel="bookmark" title="Lien permanent vers <?php the_title(); ?>">Lire la suite</a> ]
16.
</div>
17.
<?php endwhile; ?>
En m'aidant de http://codex.wordpress.org/The_Loop et du code suivant, j'ai tenté de modifier pour donner ce qui suit plus loin :
CODE
1.
<?php _e('Derniers articles parus'); ?></h3>
2.
<?php query_posts('showposts=3'); ?>
3.
<?php if (have_posts()) : while (have_posts()) : the_post();
4.
$local_ids[] = $post->ID;
5.
...
<?php _e('Derniers articles parus'); ?></h3>
2.
<?php query_posts('showposts=3'); ?>
3.
<?php if (have_posts()) : while (have_posts()) : the_post();
4.
$local_ids[] = $post->ID;
5.
...
CODE
1.
<?php
2.
// this is where the Politique module begins
3.
// passer le nombre de posts demandés de 2 à 5 pour s'assurer d'avoir un nombre suffisant de posts
4.
query_posts('showposts=5&cat=10'); ?>
5.
<h3><?php
6.
// this is where the name of the Politique category gets printed
7.
wp_list_categories('include=10&title_li=&style=none'); ?></h3>
8.
<?php while (have_posts()) : the_post();
9.
if(in_array($local_ids,$post->ID)) continue;
10.
else $post_counter++;
11.
...l'affichage du billet...
12.
if($post_counter > 2) break;
13.
<?php endwhile; ?>
<?php
2.
// this is where the Politique module begins
3.
// passer le nombre de posts demandés de 2 à 5 pour s'assurer d'avoir un nombre suffisant de posts
4.
query_posts('showposts=5&cat=10'); ?>
5.
<h3><?php
6.
// this is where the name of the Politique category gets printed
7.
wp_list_categories('include=10&title_li=&style=none'); ?></h3>
8.
<?php while (have_posts()) : the_post();
9.
if(in_array($local_ids,$post->ID)) continue;
10.
else $post_counter++;
11.
...l'affichage du billet...
12.
if($post_counter > 2) break;
13.
<?php endwhile; ?>
Et donc je fais ça :
CODE
#
#
<div class="feature clearfloat" id="lead">
#
<h3><?php _e('Derniers articles parus'); ?></h3>
#
<?php if (have_posts()) : while (have_posts()) : the_post();
#
if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
#
<?php the_date('j F Y') ?> par <?php the_author() ?> <br />
#
<a href="<?php the_permalink(); ?>" title="<?php the_title() ?>" class="title"><?php the_title() ?></a>
#
<?php the_excerpt(); ?>
#
[ <a href="<?php the_permalink() ?>" rel="bookmark" title="Lien permanent vers <?php the_title(); ?>">Lire la suite</a> ]<br /><br />
#
<?php endwhile; endif; ?>
#
</div><!--END FEATURE-->
#
<div class="feature clearfloat" id="lead">
#
<h3><?php _e('Derniers articles parus'); ?></h3>
#
<?php if (have_posts()) : while (have_posts()) : the_post();
#
if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
#
<?php the_date('j F Y') ?> par <?php the_author() ?> <br />
#
<a href="<?php the_permalink(); ?>" title="<?php the_title() ?>" class="title"><?php the_title() ?></a>
#
<?php the_excerpt(); ?>
#
[ <a href="<?php the_permalink() ?>" rel="bookmark" title="Lien permanent vers <?php the_title(); ?>">Lire la suite</a> ]<br /><br />
#
<?php endwhile; endif; ?>
#
</div><!--END FEATURE-->
CODE
#
<div id="leftcol">
#
#
<h3><?php
#
// this is where the name of the France category gets printed
#
wp_list_categories('include=5&title_li=&style=none'); ?></h3>
#
<?php $my_query = new WP_Query('category_name=france&showposts=1');
#
while ($my_query->have_posts()) : $my_query->the_post();
#
$do_not_duplicate = $post->ID; ?>
#
<div class="feature"><a href="<?php the_permalink() ?>" rel="bookmark" title="Lien permanent vers <?php the_title(); ?>"></a><a href="<?php the_permalink() ?>" rel="bookmark" class="title">
#
<?php
#
// this is where the title of the France gets printed
#
the_title(); ?></a>
#
<?php
#
// this is where the excerpt of the France gets printed
#
the_excerpt(); ?>
#
[ <a href="<?php the_permalink() ?>" rel="bookmark" title="Lien permanent vers <?php the_title(); ?>">Lire la suite</a> ]
#
</div>
#
<?php endwhile; ?>
<div id="leftcol">
#
#
<h3><?php
#
// this is where the name of the France category gets printed
#
wp_list_categories('include=5&title_li=&style=none'); ?></h3>
#
<?php $my_query = new WP_Query('category_name=france&showposts=1');
#
while ($my_query->have_posts()) : $my_query->the_post();
#
$do_not_duplicate = $post->ID; ?>
#
<div class="feature"><a href="<?php the_permalink() ?>" rel="bookmark" title="Lien permanent vers <?php the_title(); ?>"></a><a href="<?php the_permalink() ?>" rel="bookmark" class="title">
#
<?php
#
// this is where the title of the France gets printed
#
the_title(); ?></a>
#
<?php
#
// this is where the excerpt of the France gets printed
#
the_excerpt(); ?>
#
[ <a href="<?php the_permalink() ?>" rel="bookmark" title="Lien permanent vers <?php the_title(); ?>">Lire la suite</a> ]
#
</div>
#
<?php endwhile; ?>
Mais niet, les doublons demeurent au garde-à-vous !
Dan m'a dit que nous avions de grands spécialistes WP sur le Hub, donc j'espère qu'un ou deux passeront par ici pour me sortir de cette impasse.
Merci d'avance