WordPress is a popular Content Management System that is used by a great number of people. The proliferation of the use of the WordPress Content Management System all over the internet is a phenomenal thing that has happened. The rise of WordPress has also coincided with the rise of an internet filled with people who come from all walks of life.
This democratization of the ability to create on the internet is a direct result of WordPress. The high functionality and relative ease of use have enabled WordPress to become the most dominant player in the Content Management System industry. Countless creatives like, writers, artists, enthusiasts, etc. use WordPress to build and run their websites on the internet.
Now if you are a website owner who uses WordPress to pursue your creative endeavors then you want your website to be in its apex shape. Your WordPress website’s functionality will play a key role in generating leads and converting those leads into subscribers/customers.
How To Show Popular Posts In The Sidebar
One adding value to your reader/visitors is by making your website provide them with the luxury convenience. For example, if a reader likes what he or she reads on your website, they will be suggested the most popular content posts on your website. This will not only make the life of your reader easier, but also work wonders for your website’s online presence and credibility.
Therefore if you want to add the functionality of showing popular posts on the website sidebar, then we have a quick hack for you! The following points contain the step by step procedure of the hack:
Step 1 – To show the most popular posts on your website sidebar, you have to add the following code snippet to your sidebar.php file. You can choose how many posts you want to show within the sidebar by changing the number value in the $result line:
<h2>Popular Posts</h2> <ul> <?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5"); foreach ($result as $post) { setup_postdata($post); $postid = $post->ID; $title = $post->post_title; $commentcount = $post->comment_count; if ($commentcount != 0) { ?> <li><a href="<?php echo get_permalink($postid); ?>" title="< ?php echo $title ?>">< ?php echo $title ?></a> {<?php echo $commentcount ?>}</li> <?php } } ?></ul>
Step 2 – Save your sidebar.php file with the changes made and congratulations, you now have popular post suggestions on your website sidebar!