The following code will query the “blog” category for the latest three published posts and loop through these results to display the excerpt from each.
$args = array(
'category_name' => 'blog',
'post_status' => 'publish',
'posts_per_page' => 3,
);
$blog_posts = new WP_Query( $args );
if ( $blog_posts->have_posts() ):
while ( $blog_posts->have_posts() ):
$blog_posts->the_post();
// Do stuff with each post
echo get_the_excerpt() . "<br>";
endwhile;
wp_reset_postdata();
endif;
WordPress Codex is a great resource for WP development. The WP_Query class is incredibly powerful and well-documented here: https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
Related Posts:
- Use template of parent category for single post sub-categories
- How to show post(excerpt) from specific category on wp page?
- How only display all post related to category
- Different template for posts of all subcategories of category
- Category Template: Need to display different content on first page of archives
- How do I stop the loop from repeating in my category template?
- Give posts a particular template based on the assigned category
- Related post not showing table of content
- Nothing appears using get_the_excerpt() in category.php
- Show category post with excerpt text
- Display the first post’s comments of category in comments.php template
- how to style an individual page in a category [duplicate]
- How to end the excerpt with a sentence rather than a word?
- How to get the number of posts in a selected category?
- Show related posts by category but ignore one category
- Remove image caption from post excerpt
- Accessing $post variable from template part
- Most efficient way to list all categories and display a post for each of them?
- how to show all post in my page-grid.php template page
- Add custom field to category of custom post type
- Can I hide a specific post from latest posts page?
- Frontend Post Excerpt field mapping
- WordPress – Admin Manage Posts – Multiple Filters by Parent Category
- Custom Theme Want To Remove One Category From All Displays
- Divide Loop Into Days & Categories
- Select a random post from a specific category?
- Mark menu item as current-menu-item for category
- How to set up multiple taxonomies for groups of posts
- Category List (Archive) Page Template By Category
- What part of template to edit to remove category name from the top of posts?
- How to display category from recent posts?
- Can I divide the pages into categories?
- Duplicate posts and change category
- Print a message if excerpt is empty after posts have been publish/update!
- Category Foreach keeps looping?
- Setting posts_per_page for taxonomy term template
- display a random post thumbnail from a random category
- Post page to display specific category
- how to show single post in a custom template
- How to create new post content templates for my users?
- Excluding posts not working
- Limit the number of posts a category can have – newest post goes in, oldest one drops out, possible? plugin?
- Remove current category from post but display all others
- How do I show posts from another wordpress installation?
- Why won’t pagination work?
- How do I include the category next to the title of a post?
- Create a custom posts page
- How to show a custom taxonomy in the theme?
- How to import nested categories from XML file?
- Hook for changing excerpt content when excerpt not set
- Migrate posts from category and sub-category via SQL
- Posts Missing in Dashboard after update
- Display post number by category
- How to get post with slug and exclude categories
- Retrieving posts by their date and category
- Are post, page and category IDs unique to each other?
- Static pages not working
- WordPress displays post on subcategory only
- Trying to query all posts in category 4
- Output Buffer Issue with Single Post View
- How can I add a page that shows posts from a single category?
- Grab value of excerpt_length
- Prevent 404 of Author pages without posts
- Categories Listing and Highlighting current category item
- Display hierarchical categories/sub-categories for a single post only
- How to save template data into wp_post table (post_content column)
- Can I show category name in url for only one of my categories?
- Author post count in category
- Current post categories and subcatecories outside of the loop
- Why do I have categories with duplicate slugs?
- Automatic Table of contents with categories and posts
- Custom post styling per category?
- post categories – how to show only categories with a specific parent id
- Is it possible to remove actual post pages in wordpress but keep them in categories
- Need help with hiding an image within a post in a category
- WordPress not showing recent posts
- How to get post count including nested categories
- How to filter out post from a category not its subcategory in wordpress dashboard
- How can I display a specific number of post in a category via a url
- how to chang preview of list of articles of one category?
- Post of a specific category – not to be seen in paging previous/next post
- How to show main category related to that post
- Display selected category on post page
- How to arrange different post categories in template
- Add a minimum word count to Excerpt (and how to force Excerpt as a rule for WyPiekacz)
- Sort post by category using HTML Select tag
- Make assigning post to a specific category equivalent to assigning it to all categories
- How to use in_category?
- About number of posts in selected category
- How can I change the look of a post as is displayed
- Add default content to post (for specific category)
- Category page shows “No Posts” but I do have two assigned
- Exclude a ‘portfolio’ custom category?
- ‘get_previous_post’ in same category returning (!empty) when no previous post in category exists
- How do I create a template page to show 3 blog posts?
- How can I get on the same row two post of different categories?
- How to sort the post to a specific category
- How can I fixe the article title problem?
- Automatically select category based on user role
- Filters do not work when there are multiple (one works)