Only show unique articles in a triple loop
-
I am trying to do a three category loop but I need all articles to be unique eg if one is in the first list then don’t show it in the 2nd or 3rd loop.
This comes in to play because one article could be under three different categories.
So my code is currently as below. It generates what you see in the screenshot above. An example of what I don’t want there is the “Should I Take The JLPT” article. It should only show in the first loop but not the other two loops below it eg every article should only ever appear once across the three loops.
<h3>TOP LEARNING ARTICLES</h3> <dl class="entryList small"> <dt>Kanji</dt> <?php query_posts('category_name=learn-kanji&showposts=5&orderby=comment_count&order=DESC'); $kanji_ids = array(); while (have_posts()) : the_post(); $kanji_ids[] = get_the_ID(); ?> <dd><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></dd> <? endwhile; ?> </dl> <dl class="entryList small"> <dt>Hiragana</dt> <?php query_posts('category_name=learnhiragana&showposts=5&orderby=comment_count&order=DESC&cat=-8'); $hiragana_ids = array(); while (have_posts()) : the_post(); $hiragana_ids[] = get_the_ID(); ?> <dd><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></dd> <? endwhile; ?> </dl> <dl class="entryList small"> <dt>Grammar/Vocab</dt> <?php query_posts('category_name=vocabulary&category_name=grammar&showposts=5&orderby=comment_count&order=DESC'); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?><dd><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></dd> <?php endwhile;endif; wp_reset_query(); ?></dl>
Thanks for any help.
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘Only show unique articles in a triple loop’ is closed to new replies.