Avoid featured post duplication in several blocks of latest post by category
-
Hello everybody,
First, sorry for my english, if you don’t understand me, don’t hesitate to tell !So, in my homepage I would like to have a big block with a featured post, which is the latest post (of any category) and 3 smaller blocks which display one last article from 3 categories.
I succeed to do that (yes, because, in addition to be french, I’m a newbie to wordpress, and code…). But I still have a problem : the featured post can also appear in a last post per category block.
I tried some things based on the documentation of the Loop but it didn’t work. So I will be greatful if someone could help me !Here is the code in the file of the “featured template” of this theme where I add a “$do_not_duplicate” (and if someone can explain me the signification of the attributes of the array, it could be great) :
// Query featured entries $featured = new WP_Query( array( 'no_found_rows' => false, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, 'ignore_sticky_posts' => 1, 'posts_per_page' => ot_get_option('featured-posts-count'), 'cat' => ot_get_option('featured-category') ) ); ?> <?php if ( is_home() && !is_paged() && ( ot_get_option('featured-posts-count') =='1') ): // No slider if 1 post is featured ?> <div class="featured"> <?php while ( $featured->have_posts() ): $featured->the_post(); ?> <?php $do_not_duplicate = $post->ID; // permet d'éviter la duplication dans les catégories de la page d'accueil ?> <?php get_template_part('content-featured'); ?> <?php endwhile; ?> </div><!--/.featured-->
And here is a part of the code of my homepage where we find the 3 loops to display one post per category :
<?php // Nouvelles Queries WP pour l'affichage d'un article par catégorie $qualite_eau = new WP_Query('category_name=qualite-de-leau&showposts=1'); $act_littorales = new WP_Query('category_name=act-littorales&showposts=1'); $cours_eau = new WP_Query('category_name=cours-eau&showposts=1'); ?> <!-- some code--> <div class="pad group"> <?php get_template_part('inc/featured'); ?> <?php if ( have_posts() ) : ?> <?php if ( ot_get_option('blog-standard') == 'on' ): ?> <?php while ( have_posts() ): the_post(); ?> <?php get_template_part('content-standard'); ?> <?php endwhile; ?> <?php else: ?> <div class="post-list group"> <!-- Boucles multiples pour appeler le dernier article de chaque catégorie --> <div class="post-row"> <?php while ($qualite_eau->have_posts()) : $qualite_eau->the_post(); ?> <?php if($post->ID == $do_not_duplicate) continue; update_post_caches($posts); // Evite la duplication de l'article à la Une ?> <?php get_template_part('content'); ?> <?php endwhile; ?> </div> <div class="post-row"> <?php while ($act_littorales->have_posts()) : $act_littorales->the_post(); ?> <?php if($post->ID == $do_not_duplicate) continue; update_post_caches($posts); ?> <?php get_template_part('content'); ?> <?php endwhile; ?> </div> <div class="post-row"> <?php while ($cours_eau->have_posts()) : $cours_eau->the_post(); ?> <?php if($post->ID == $do_not_duplicate) continue; update_post_caches($posts); ?> <?php get_template_part('content'); ?> <?php endwhile; ?> </div> </div><!--/.post-list--> <?php endif; ?>
Hope to hear from you soon !
Theme : Hueman (child theme)
- The topic ‘Avoid featured post duplication in several blocks of latest post by category’ is closed to new replies.