Vitalij
Vitalij

Reputation: 680

WORDPRESS: List of all categories with limited number of posts (on main page)

Can someone resolve second problem:

I wanna list all categories on main page of my website, and each category will show only 4 last posts with title and favorite image.

How to do this, help me, please :)

Upvotes: 0

Views: 818

Answers (1)

Vitalij
Vitalij

Reputation: 680

<?php  $cats = get_categories('orderby=count&order=DESC'); 

foreach ($cats as $cat) :

  $args = array(
  'posts_per_page' => 1, // max number of post per category
  'cat' => $cat->term_id
  );
  query_posts($args);
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    <!-- show the ususal stuff in the loop -->
    <?php endwhile; endif; wp_reset_query(); ?>

<?php endforeach; ?>

Upvotes: 1

Related Questions