• Resolved nandayo

    (@nandayo)


    Hello,

    I’m currently using the query:

    <?php
    	$categories = get_categories('hide_empty=1');
    	foreach ($categories as $category) :
    	query_posts("showposts=1&cat=" .$category->cat_ID);
    	if (have_posts()) : the_post();
    	?>

    to show the latest post from every category on my front page.

    Because I’m using child categories I have many double posts on my front page. How can I remove the double posts? (I have a category named CAT and a child category named CHILD. CAT is empty and CHILD containts a post. Why does WP show up the post two times? ?? )

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Assuming you don’t put posts in more that one category, this should work:

    <?php
    $categories = get_categories('hide_empty=1');
    foreach ($categories as $category) {
      if ($category->count > 0 ) {
        $args=array(
          'cat' => $category->cat_ID,
          'showposts'=>1,
          'caller_get_posts'=>1
        );
        $catposts=get_posts($args);
        if ($catposts) {
          foreach($catposts as $catpost) {
            echo "<a href='".get_permalink($catpost->ID)."'>".$catpost->post_title."</a>
    ";
          }
        }
      }
    }
    ?>

    Note:
    By WordPress standards, ANY category that has been designated a Parent category is not meant to be checked in the category hierarchy when writing posts. Meaning, only the latest generation category should be checked. Think of it like this, only the youngest generation gets the action.

    Thread Starter nandayo

    (@nandayo)

    Thank you very much, Michael!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show latest posts but no double posts’ is closed to new replies.