'How do I show custom recent posts in WordPress?
Now it's showing like this: now it's showing like this
I want it to look like this: I want it to look like this
Solution 1:[1]
There are two ways to do:
In your WordPress dashboard, go to Appearance » Widgets and add the ‘Recent Posts’ widget to your sidebar. https://prnt.sc/1rhjdc4
Using wp query
$args = array(
'post_type' => 'product',
'posts_per_page' => 10,
);
$loop = new WP_Query($args);
while ( $loop->have_posts() ) {
$loop->the_post();
?>
<div class="entry-content">
<?php the_title(); ?>
<?php the_content(); ?>
</div>
<?php
}
Solution 2:[2]
wp_get_recent_posts( array $args = array(), string $output = ARRAY_A ) Please read this article https://developer.wordpress.org/reference/functions/wp_get_recent_posts/
<?php
$recent_posts = wp_get_recent_posts();
foreach( $recent_posts as $recent ) {
printf( '<li><a href="%1$s">%2$s</a></li>',
esc_url( get_permalink( $recent['ID'] ) ),
apply_filters( 'the_title', $recent['post_title'], $recent['ID'] )
);
}
?>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | ZealousWeb |
Solution 2 | HafizHamzaCS |