How To Display Fresh Posts From A Specific Column In WordPress

5 minutes read

Have you ever had a need to bring your fresh posts from each separate column to your WordPress sidebar? Recently, one of our users asked us if there was a way to quickly bring up fresh posts from a specific category to the WordPress sidebar widget. In today’s article, we will show you how to display the latest posts for each rubric in the WordPress sidebar.

There are two ways to display fresh posts from each individual column in WordPress. The first method is really simple and convenient for beginners, because it is supposed to use a plugin to display entries in the widget (no need to bother with the code).

The second method uses a snippet of code for (suitable for advanced users), and you will be able to implement your plans without a plugin.

The only advantage of using the code is that you will not depend on the plugin, and you can also customize the output in more detail. However, the way with the plug-in is simpler and allows you to configure options that will satisfy 95% of people (this is displaying the recording thumbnail, displaying the recording quotation and controlling its length, displaying the recording date and the number of comments, etc.)

We Display Fresh Entries From Each Category (Using The Plugin)

First of all, you need to install and activate the Category Posts Widget plugin .

After activation, you must go to the Appearance section »Widgets , where you will find a new widget called Category Posts in the list of available.

Just drag the Category Posts widget to the sidebar to the place where you want to display the latest entries from the category.

category-posts-plugin-settings [1]

Widget options speak for themselves. First you need to specify the title for the section of the heading entry, and then select the heading itself. After that, you can configure other display options, such as the number of records, quote, thumbnail, etc.

After completing the settings, click on the save button settings widget. You can go to the site to see the work of the widget in action.

We Display Fresh Entries From Each Column Without A Plugin (Code)

In this method, we will use a code snippet to display fresh entries from a specific category.

First, you need to add the following code to the functions.php file of your theme or to the plugin for the WordPress site :

1 function devise_postsbycategory() {
2 // request
3 $the_query new WP_Query( array'category_name' => 'announcements''posts_per_page' => 10 ) );
5 // Cycle
6 if $the_query->have_posts() ) {
7     $string .= '<ul class="postsbycategory widget_recent_entries">';
8     while $the_query->have_posts() ) {
9         $the_query->the_post();
10             if ( has_post_thumbnail() ) {
11             $string .= '<li>';
12             $string .= '<a href="' . get_the_permalink() .'" rel="bookmark">'. get_the_post_thumbnail($post_idarray( 50, 50) ) . get_the_title() .'</a></li>';
13             else {
14             // if no featured image is found
15             $string .= '<li><a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_title() .'</a></li>';
16             }
17             }
18     else {
19     // no records found
20 }
21 $string .= '</ul>';
23 return $string;
25 /* Restoring the original recording data */
26 wp_reset_postdata();
27 }
28 // Adding a shortcode
29 add_shortcode('categoryposts''devise_postsbycategory');
31 // We activate the execution of the shortcode in the text widget
32 add_filter('widget_text''do_shortcode');

Make sure you replace the ‘announcements’ with your heading slug.

The code simply queries WordPress in order to get 10 entries from a specific category. He then displays these entries as a bulleted list. If the recording has a thumbnail image, then it will display it.

In the end, we created the ‘categoryposts’ shortcode and activated its execution in the site text widgets.

There are three ways to display fresh entries from a specific category using the code above.

First, you can simply paste the following code anywhere in the site template where you want to display the list (for example, footer.php, single.php, etc.)

1 <?php devise_postsbycategory() ?>

The second and third methods involve the use of shortcode in widgets or inside your posts / pages.

Just go to the Appearance section »Widgets and add a text widget to your sidebar. Now add the [categoryposts] shortcode to the text widget and save it. Now you can go to the site to see the latest posts from a specific section in the sidebar.

If you want to display new posts from a category on a specific page or post, simply insert the shortcode in the post content area.

By default, your list will most likely not look very nice. You will need to use CSS to style the list of category entries. You can use the code below as a starting point in the theme style sheet.

view source

print out?

1 ul.postsbycategory {
2 list-style-typenone;
3 }
5 .postsbycategory img {
6 float:left;
7 padding:3px;
8 margin:3px;
9 border3px solid #EEE;
10 }


Facebook Twitter LinkedIn Telegram Pocket

Related Posts:

To transfer blog posts from one WordPress site to another, you can follow these steps:Export the blog posts: On the WordPress site you want to transfer the blog posts from, go to the WordPress dashboard and navigate to the &#34;Tools&#34; section. Click on &#3...
Filtering posts in WordPress by category allows you to display only the posts that belong to a specific category or categories. This can be helpful if you want to create custom pages or sections on your website that focus on specific topics.To filter posts by ...
If the content on your site is correctly organized by headings, then you probably will not need the block “Similar entries” on the site, because you can simply display fresh entries from the same heading. In today’s article, we will show you how to create a se...