• Hi everyone,

    I’m currently trying to figure out how to fix up my home page.

    What I want to do is show only 1 post per category (the newest post). The catch is that I have more than 10 categories and I only want to show 10 posts. I know it’s possible, but probably difficult.

    In other words, I only want 10 topics showing on my homepage, 1 post from each topic, without specifying any specific category. Kind of like:

    Homepage on Monday-
    Newest post from Category 10
    Newest post from Category 3
    Newest post from Category 6

    Homepage on Tuesday-
    Newest post from Category 21
    Newest post from Category 12
    Newest post from Category 1

    Can anyone help me out with this?

    Many thanks in advance for any who try,
    Fadere

Viewing 3 replies - 1 through 3 (of 3 total)
  • <?php
    $num_cats_to_show = 10;
    $count = 0;
    $taxonomy = 'category';//  e.g. post_tag, category
    $param_type = 'category__in'; //  e.g. tag__in, category__in
    $term_args=array(
      'orderby' => 'name',
      'order' => 'ASC',
    );
    $terms = get_terms($taxonomy,$term_args);
    if ($terms) {
      foreach( $terms as $term ) {
        $args=array(
          "$param_type" => array($term->term_id),
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => 1,
          'caller_get_posts'=> 1
          );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          $count ++;
          if ($count <= $num_cats_to_show) {
            while ($my_query->have_posts()) : $my_query->the_post(); ?>
              <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
             <?php
            endwhile;
          }
        }
      }
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
    Thread Starter Fadere Made

    (@fadere)

    awesome!

    I’ll have to mess around with that coding when I’m more awake lol.

    Thank again!
    Fadere

    Thanks,

    Like i show in my site: There is a number of categories that not change, because i want administrate it. I want to put usefull information on each category, and when the people coming inside the category linked could find usefull information written by me. Only 2 categories in my blog will have permision to make comments. In the home page i want show the name of the categories in the first column and decide wich post will be shown in the body.

    Looking forward to your comments,

    And thanks again for try to advise me.

    Best regards,

    Arxa.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How To Show 1 Post Per Category On Home Page, Max 10 Posts’ is closed to new replies.