WordPress Popular Posts is one of the most popular plugins for displaying popular posts (based on the number of views) in WordPress.
This tutorial provides the steps to display 3 most popular posts in columns with image, title and category appearing one below the other in each post in a custom “Home Featured” widget area below the header on the homepage in Genesis.
Note: The plugin does not currently support showing all the categories and only shows one at the moment. Apparently, support for multiple categories is coming in the next version.
Step 1
Install and activate WordPress Popular Posts.
Step 2
Add the following in child theme’s functions.php:
// Register home-popular widget area.
genesis_register_widget_area(
array(
'id' => 'home-popular',
'name' => __( 'Home Popular', 'my-theme-text-domain' ),
'description' => __( 'Place a Popular Posts widget in here.', 'my-theme-text-domain' ),
)
);
add_action( 'genesis_after_header', 'custom_popular_posts' );
/**
* Display Popular Posts below the site header on homepage.
*/
function custom_popular_posts() {
// if we are not on the front page, abort.
if ( ! is_front_page() ) {
return;
}
// display `home-popular` widget area.
genesis_widget_area( 'home-popular', array(
'before' => '<div class="home-popular widget-area"><div class="wrap">',
'after' => '</div></div>',
) );
}
Step 3
At Appearance > Widgets, drag a WordPress Popular Posts widget into the Home Popular widget area and configure it.
Here’s the custom Post HTML Markup:
<li><div class="entry-img">{thumb}</div><div class="entry-info">{title}<span class="entry-cats">{category}</span></div></li>
Step 4
Add the following in child theme’s style.css and modify to suit:
.home-popular {
padding: 60px 0;
background-color: #fff;
}
.home-popular .widget-title {
margin-bottom: 40px;
font-size: 30px;
}
.popular-posts .wpp-list {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
}
.popular-posts .wpp-list > li {
float: left;
clear: none;
width: 31.25%;
margin-bottom: 0;
border-radius: 3px;
border-top-left-radius: 0;
border-top-right-radius: 0;
-webkit-box-shadow: 0 2px 4px 0 rgba(0,0,0,0.2);
box-shadow: 0 2px 4px 0 rgba(0,0,0,0.2);
}
.entry-img {
overflow: hidden;
border-bottom: 4px solid #ffe131;
}
.popular-posts .wpp-thumbnail {
margin-right: 0;
-webkit-transition: all 0.4s ease-in-out;
transition: all 0.4s ease-in-out;
}
.entry-img a:hover img {
-webkit-transform: scale(1.04);
transform: scale(1.04);
}
.entry-info {
padding: 12px;
}
.wpp-list a {
color: #464646;
text-decoration: none;
}
.wpp-list a:hover {
color: #000;
}
.wpp-post-title {
display: block;
font-size: 16px;
font-weight: bold;
}
.entry-cats {
font-size: 13px;
}
@media only screen and (max-width: 860px) {
.popular-posts .wpp-list {
flex-direction: column;
-webkit-box-direction: normal;
-webkit-box-orient: vertical;
-ms-flex-direction: column;
}
.popular-posts .wpp-list > li {
width: 100%;
margin-bottom: 40px;
}
}
Would the CSS be shorter if ‘display: grid’ was used?
if IE/Edge support is not needed, yes. Otherwise, no.
As you have probably noticed, CSS includes code for adding box-shadow, border-radius, border etc. besides just arranging the posts in side-by-side columns.
Hi there! Thanks again for doing this tutorial. I really appreciate it.
My problem with HTML Markup is that the fields are not showing when checked. http://prntscr.com/gkl622
You’ll find the fields after you click Save in the widget.
Ah, thanks! Nice for featured posts.
Cheers!
Hi, I can only display my popular posts in my sidebar. What do I need to do to display them in a section of a Page? I’m using Mai theme and I don’t have access to my functions.php. https://staging2.bitingintolife.net/hp/
Im getting a php error when adding the code to function.php
Your PHP code changes were rolled back due to an error on line 15 of file wp-content/themes/Avada-Child-Theme/functions.php. Please fix and try saving again.
Uncaught Error: Call to undefined function genesis_register_widget_area() in wp-content/themes/Avada-Child-Theme/functions.php:15
Stack trace:
#0 wp-settings.php(585): include()
#1 wp-config.php(104): require_once(‘/home/customer/…’)
#2 wp-load.php(50): require_once(‘/home/customer/…’)
#3 wp-admin/admin.php(34): require_once(‘/home/customer/…’)
#4 wp-admin/theme-editor.php(10): require_once(‘/home/customer/…’)
#5 {main}
thrown
Hey Jason. This tutorial is meant only for sites that use Genesis as the parent theme.
You are using Avada. This won’t work in your case.