How to query different categories on index?

You could get the categories and for each of them, you use the list category posts plugin shortcode to echo the relevant posts into a div:


     $categories = get_categories(); 
      foreach ($categories as $category) {
        echo '<div>';
        $cat=$category->cat_name;
        echo do_shortcode( '[catlist id='.$cat.' numberposts=5 ]');
        echo '</div>';
     }

This goes in the ‘latest posts’ part of your blog index. Then you can style each div to fit your theme’s layout (floated left, min-width)

Without making use of any plugin you could change the code this way:


     $categories = get_categories(); 
      foreach ($categories as $category) {
        echo '<div>';
        $cat=$category->cat_name;
        $args=array(
          'post_type' => 'post',
          'post_status' => 'publish',
          'category_name' => $cat,
          'posts_per_page' => 5,
          'ignore_sticky_posts'=> 1
        );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
            while ( $my_query->have_posts() ) : $my_query->the_post();
                echo '<h1><a href="https://wordpress.stackexchange.com/questions/181527/.the_permalink().">'.the_title().'</a></h1>';
            endwhile;
        } //endif
        wp_reset_postdata();
        echo '</div>';
     } //foreach