How To Display Recent Posts In Wordpress

The Display Posts Shortcode allows you to địa chỉ a list of your blog posts to lớn different pages. Using Arguments you can display specific posts based on their categories or tags.

Bạn đang xem: How to display recent posts in wordpress

Shortcodes are small snippets of code designed for that allow you to showroom different features lớn your site or blog. More information on shortcodes can be found here.

Table of Contents

If you added the shortcode before upgrading to lớn the Business or eCommerce plans, your code would render the nội dung once you install aDisplay Posts Shortcode plugin. Various plugins offer similar functionality.

Alternatively, you can also consider the Blog Posts or Latest Posts blocks.

Display Posts Shortcode Overview

There are a number of reasons why you might want to lớn use the Display Posts shortcode.

You want to show a short danh sách of posts on your trang chủ page, & the featured posts option is either not part of your theme, or not displaying posts the way you want.You want lớn create a page of Authors, with bios, và some of their most recent published works on your site.You want khổng lồ highlight specific posts, lượt thích announcements, on a page.You want to địa chỉ a specific các mục of posts to lớn a widget in your sidebar or footer.Much more.

↑ Table of Contents ↑

Adding the Shortcode

The following instructions will work for editing a Page, a Post, or Text Widget. When you add the following code, you will only see the code placeholder in the editor. But, when you publish your page, you’ll see the result of the shortcode.

Edit a page, post, or text widget.Add the shortcode in a post or page.Publish or Update your page/post.

If you’re using the Blocks Editor you can also showroom a Shortcode block to địa chỉ cửa hàng the Display Posts shortcode.


New posts, and updates to existing posts can take up lớn one hour lớn be displayed anywhere you are using this shortcode.

This is how the Display Posts shortcode looks on a live page using the Twenty Seventeen theme.

The Display Posts shortcode will show a bulleted các mục of the 10 most recent posts by default. It is possible lớn customize the number of posts as well as the style, và what elements of the posts show in the danh sách (title, featured images, excerpts, etc).

Xem thêm: Chứng Khoán Phái Sinh Tiếng Anh Là Gì ? Công Cụ Phái Sinh Phổ Biến

↑ Table of Contents ↑

Display Arguments

Arguments are used to customize how the posts are displayed. Below is a menu of common arguments you can add to your Display Posts shortcode & examples of how the shortcode should look with the argument added.

authorSpecify the post authorDefault: emptyExample:

categorySpecify the category slug (or comma separated các mục of category slugs). View this shortcode in action on this example site.Default: emptyExample:

date_formatSpecify the date format used when include_date is true. See Formatting Date & Time on the Codex for more information.Default: ‘(n/j/Y)’Example:

idSpecify a specific post ID (or multiple post IDs) to lớn display.Default: emptyExample:

image_sizeSpecify an image size for displaying the featured image, if the post has one. The image_size can be set khổng lồ thumbnail, medium, large (all controlled from Settings > Media).Default: emptyExample:

if you’re using a theme that supports nội dung Options, and have it set khổng lồ not show featured images on Pages, the image_size argument will also have no effect on shortcodes used on a page on the site – featured images will not show for any posts added via the shortcode even if the shortcode says they should be shown.

include_contentInclude the full post nội dung after the title.Default: emptyExample:

include_excerptInclude the post’s excerpt after the title (and date if provided).Default: emptyExample:

offsetThe number of posts to pass overDefault: 0Example:

orderSpecify whether posts are ordered in descending order (DESC) or ascending order (ASC).Default: DESCExample:

orderbySpecify what the posts are ordered by. See the available parameters here.Default: dateExample:

portfolio_typeIf you are using the Portfolio post type, use this to get items from a specific portfolio type.

post_parentDisplay the pages that are a child of a certain page. You can either specify an ID or ‘current’, which displays the children of the current page.Default: emptyExample:

post_statusShow posts associated with a certain post statusDefault: publishExample:

post_typeSpecify which post type lớn use. You can use a mặc định one (post or page). For Portfolios use “jetpack-portfolio”. Similarly, for Testimonials use “jetpack-testimonial”.Default: postExample:

posts_per_pageHow many posts to display.Default: 10Example:

tagSpecify the tagslug (or comma separated các mục of tagslugs)Default: emptyExample:

taxonomy, tax_term, and tax_operatorUse these parameters to bởi vì advanced taxonomy queries. Use ‘taxonomy’ for the taxonomy you’d like to query, ‘tax_term’ for the term slug (or terms) you’d lượt thích to include, and ‘operator’ to change how the query uses those terms (most likely this field will not be needed).Default: ‘taxonomy’ = empty , ‘tax_term’ = empty , ‘tax_operator’ = ‘IN’Example:

wrapperWhat type of HTML should be used to lớn display the listings. It can be an unordered các mục (ul), ordered danh mục (ol), or divs (div) which you can then style yourself.Default: ulExample:

↑ Table of Contents ↑

Customization Examples

Here are some examples of shortcodes combining multiple arguments to display a specific menu of posts.

This will menu the 20 most recent posts with the tag ‘advanced’.

This will list the 10 most recent posts tagged ‘Advanced’ & display a post image using the ‘Thumbnail’ size.

This will list every post in the Must Read category, in alphabetical order, with the date appended to lớn the end.

This will display posts as an ordered list. Options are ul for unordered lists (default), ol for ordered lists, or div for divs.

This will display only the posts with an ID of 14 và 3.

↑ Table of Contents ↑

Image Alignment

A common request is khổng lồ display a list of posts with title, excerpt, và the thumbnail aligned khổng lồ the right. Here’s the shortcode you might use:

This includes the excerpt, adds an image of the “thumbnail” size (you can customize the image sizes in Settings → Media), & tells it to lớn present the danh mục without bullets.

In order to get the image floating lớn the right, add this to lớn your custom CSS file (requires the Premium or Business upgrade):

.display-posts-listing .alignleft float: right; margin: 0 0 5px 5px;

↑ Table of Contents ↑

(Advanced) Multiple Taxonomy Queries

While most people will only ever need a single taxonomy query, this shortcode supports an infinite number of taxonomy queries. Let’s say you wanted lớn get all posts in the category “featured” & also tagged “homepage”. We’ll use a shortcode that looks lượt thích this:

If you wanted to lớn get all posts in the category “featured” that are also tagged either “blue” or “green”, you could use a shortcode that looks lượt thích this:

You can string as many of those as you like, just start the count at 2. In the field listing below, replace (count) with an actual number.

Here are the available fields:

taxonomy_(count)Which taxonomy lớn queryDefault: empty

tax_(count)_termWhich terms khổng lồ include (if more than one, separate with commas)Default: empty

tax_(count)_operatorHow khổng lồ query the terms (IN, NOT IN, or AND)Default: IN

tax_relationDescribe the relationship between the multiple taxonomy queries (should the results match all the queries or just one of them). Available options: và and ORDefault: AND

↑ Table of Contents ↑


TheDisplay Posts Shortcode has a limit of 100 posts displayed.

↑ Table of Contents ↑

How lớn Find the Post ID

You can find the Post ID in the Edit Post URL on your post editor. For example, the Post ID for the following example is “125.”