Answer the question
In order to leave comments, you need to log in
How to display multiple categories with Wordpress posts?
Good evening.
Task:
On the main page, I want to display the categories. All who are created and who are.
But they should be limited to only three entries .
Visually something like this:
In letters something like this:
Рубрика 1 Рубрика 2 Рубрика 3
Запись 1 Запись 1 Запись 1
Запись 2 Запись 2 Запись 2
Запись 3 Запись 3 Запись 3
<section>
<?php $posts = get_posts ("category=12&orderby=date&order=ASC&numberposts=3"); ?>
<?php if ($posts) : ?>
<?php foreach ($posts as $post) : setup_postdata ($post); ?>
<div class="block">
<div class="name">
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</section>
Answer the question
In order to leave comments, you need to log in
Something like that
<?php
$categories = get_categories();
foreach( $categories as $category ) {
echo $category->name;
$posts = get_posts( array(
'post_type' => 'post',
'posts_per_page'=> 3,
'category' => $category->term_id
) );
foreach( $posts as $post ) {
echo $post->post_title;
}
}
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question