Please refer the below code for displaying WordPress posts from a specific category.
- <?php
- $the_query = new WP_Query(array(
- 'category_name' => 'category_name',
- 'post_status' => 'publish',
- 'posts_per_page' => 10,
- ));
- ?>
- <?php if ($the_query->have_posts()) : ?>
- <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
- <?php the_title(); ?>
- <?php the_excerpt(); ?>
- <?php the_post_thumbnail(); ?>
- <?php the_content(); ?>
- <?php endwhile; ?>
- <?php wp_reset_postdata(); ?>
- <?php else : ?>
- <p><?php __('No Posts found'); ?></p>
- <?php endif; ?>