Answer the question
In order to leave comments, you need to log in
How to hide the last published post?
The page displays the announcement of the last published post with a thumbnail, under it the name of 3 posts with thumbnails horizontally is displayed. How can I make sure that the one above is excluded from these 3 posts.
<div class="description">
<?php $query1 = new WP_Query (array(
'category_name' => 'рецепты',
'posts_per_page' => '1',
));
while($query1->have_posts()) : $query1->the_post(); ?>
<a href="<?php the_permalink(); ?>"><h2 class="title"><?php the_title(); ?></h2></a>
<div class="thumbnail"><?php the_post_thumbnail(); ?></div>
<?php the_excerpt() ?>
<a href="<?php the_permalink(); ?>">Читать далее</a>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<div class="recipes">
<div class="row">
<a href="<?php echo get_page_link( 29 ); ?>"><h2><?php echo get_cat_name(28);?></h2></a>
<?php $query2 = new WP_Query(array(
'category_name'=>'рецепты',
'posts_per_page'=> 3,
));
while($query2->have_posts()) : $query2->the_post(); ?>
<div class="col-md-4">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?><h2 class="title"><?php the_title(); ?></h2></a>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
</div>
Answer the question
In order to leave comments, you need to log in
You can do as Ilya
advises in the neighboring council. This way you will make fewer requests.
the only thing you will need then is 'posts_per_page' => '4',
But if you have these two pieces of code in the template displayed in different places, and together you showed them here only for clarity, then it might be better to do it differently.
Two options how to do it:
1 in the second query specify 'offset' => 1
2 or also in the second query specify 'post__not_in' => array('id of the excluded post')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question