Answer the question
In order to leave comments, you need to log in
Display articles of each Wordpress category?
Hello.
How can you display articles of different categories in this way: for example, there are 4 containers, in these containers you need to place 5 articles in each block of different categories. For example, in one container there will be 5 articles of one category, in another container 5 articles of another category, etc.
There is this code:
<article class="service-content__block">
<div class="service-content__wrap">
<img src="images/img.png" alt="" class="service-content__image">
</div>
<div class="service-content__right">
<h3 class="service-content__title"><?php echo get_cat_name(9);?></h3>
<?php
$id=9;
$n=6;
$recent = new WP_Query("cat=$id&showposts=$n");
while($recent->have_posts()) : $recent->the_post();
?>
<a class="service-content__link" href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a>
<?php endwhile; ?>
</div>
</article>
<article class="service-content__block">
<div class="service-content__wrap">
<img src="images/img.png" alt="" class="service-content__image">
</div>
<div class="service-content__right">
<h3 class="service-content__title"><?php echo get_cat_name(10);?></h3>
<?php
$id=10;
$n=6;
$recent = new WP_Query("cat=$id&showposts=$n");
while($recent->have_posts()) : $recent->the_post();
?>
<a class="service-content__link" href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a>
<?php endwhile; ?>
</div>
</article>
Answer the question
In order to leave comments, you need to log in
Get all categories into an array, then foreach iterate through the array
Like this...
$cats = get_categories(); // или только нужные категории
foreach ( $cats as $cat){
WPQuery .... $cat->ID
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question