Answer the question
In order to leave comments, you need to log in
How to display the latest posts on the main page with thumbnails?
The site has several custom post types, for example, there are "promotions" and "articles"
Now I'm struggling with displaying the last 6 posts from the custom post type "promotions" on the main page, please help.
<?php
$args = array(
'numberposts' => 6,
'post_type' => 'akcii',
'post_status' => 'publish',
);
$result = wp_get_recent_posts($args);
foreach( $result as $p ){
?>
<div class="col-12 col-sm-6 col-lg-4">
<div class="main-articles_block">
<div class="main-articles_header"><?php echo $p['post_title'] ?></div>
<a href="<?php echo get_permalink($p['ID']) ?>">
<?php the_post_thumbnail('actions-preview', ''); ?>
</a>
<div class="main-articles_descr">
<div>
<a href="<?php echo get_permalink($p['ID']) ?>">Далеко-далеко за словесными горами в стране, гласных и согласных живут рыбные тексты.</a>
</div>
</div>
</div>
</div>
<?php
}
?>
Answer the question
In order to leave comments, you need to log in
Fix your query and loop like this. Will work.
<?php
$args = array(
'post_type' => 'akcii',
'posts_per_page' => 6,
);
$recent = new WP_Query( $args );
while ( $recent->have_posts() ) {
$recent->the_post();
?>
<div class="col-12 col-sm-6 col-lg-4">
<div class="main-articles_block">
<div class="main-articles_header"><?php echo get_the_title(); ?></div>
<a href="<?php echo get_permalink();?>">
<?php the_post_thumbnail('actions-preview', ''); ?>
</a>
<div class="main-articles_descr">
<div>
<a href="<?php echo get_permalink(); ?>">Далеко-далеко за словесными горами в стране, гласных и согласных живут рыбные тексты.</a>
</div>
</div>
</div>
</div>
<?php
}
wp_reset_postdata();
wp_reset_query();
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question