Displaying popular or most-read articles, or displaying the most recent articles within your site encourages visitors to browse more content published on the site, in addition to making it easier for visitors to access the content within your site, which helps increase interaction as well as increase the length of time the visitor stays on your site for a period of time. Longer.
Also, showing the most popular or newest articles on the site may significantly improve the site’s SEO , as showing these articles encourages the visitor to enter and browse them, thus increasing the period of his stay on the site, which in turn is reflected in improving the site’s SEO, as the longer the visitor stays. Within the site, the more search engines trust it and give it priority in ranking high in search results.
Ways to show the most popular or newest articles on your WordPress site
In this article, we will learn about several different ways to display the most read or most recent articles on the site. Through these methods, you will also learn how to control the style and method of displaying articles on your site and arrange them in the way you want. In the following paragraphs, we will explain:
- How to show the most popular articles using an extension
- How to show the latest posts using the WordPress editor
- How to show the most popular articles using PHP code plugin
The image above shows the (Educational Guides) section that appears on the far left of the screen on the WordPress Arabic site, which contains some useful articles for readers. This is an illustrative example of what we will do during the current article in which we explain the ways to show a group of distinctive articles to readers, along with the content. What they are currently reading on the site.
1. Show the most popular articles using plugins
There are many WordPress plugins that can be used to show the most popular posts within your site in the place you prefer.
We will explain one of the free plugins that provides you with multiple options to display the most popular articles on your site in an easy way and without the need for complex programming skills.
The WordPress Popular Posts plugin allows you to display the most popular articles within your site, and provides you with many options for controlling the look and feel of displaying those articles, as you can choose from many display designs and appearances. You can also control the type of popular articles and the way they are displayed according to the total number of visits. Which you got, or by the number of comments. And other options that we will discuss in detail in the following paragraphs.
After installing and activating the plugin on your site, go directly to the WordPress control panel, then go to: Appearance > Widgets , and click on the plugin’s widget titled (WordPress Popular Posts) and choose the place where you want the most popular articles to appear, such as the site’s sidebar:
After choosing the place where you want to show the most popular articles, click on the (Add Widget) button and the widget will be added in the place you chose. You will notice that the widget dialog box for adding contains many options as shown in the following image:
- Title: Place the title that appears at the top of the popular articles display box within your site. Write, for example, “Most Viewed” or any other appropriate title.
- Show up to: Select the maximum number of popular articles you want to show.
- Sort posts by : You can choose whether to arrange or sort the articles according to the number of views or the number of comments made on them.
- Filters is for creating filters on the most popular articles. You will find several options to control the display of popular articles, such as choosing whether you want to display popular articles within 24 hours only or within a week or month, or you can choose All time to select the most popular articles all the time, starting from From the time the add-on was installed on the site. You can also exclude some articles from being displayed within the Most Popular box through the Post ID(s) to exclude box , in which you put the ID number of the article that you do not want to appear.
This add-on is also compatible with online stores operated by WooCommerce, where you can choose products or their categories to appear within the most popular or most viewed products box within your store:
The add-on also shows you many other options as follows:
5. post settin : It contains options to control the look and feel of displaying the most common articles, such as the option to reduce the title length of articles. You can also choose whether you want to show the summary of the article next to its title or hide it. The Display post thumbnail option appears before you , through which you specify what If you want to display the featured image of the article or hide it and just display the title and summary or just the title.
6. stats tag settings : You can choose to display the number of comments below the article title, or display the number of views, the name of the writer, the date of publication, and other information related to this article, which helps you fully control the way the section of the most popular articles on your site is displayed.
At the end of the widget’s settings bar, you will find the (Theme) tab, which contains a list of 10 options. You can switch between them and choose any of them to change the shape and design of the box for showing the most popular articles within the site:
After completing all the settings for the widget, here is an example of the most popular article box that will appear on your site in the place you previously chose:
2. Show the latest posts and control them from within the WordPress editor
Within the WordPress editor, you will find some components that help you insert other articles into the current article or page that you are editing, and one of the most famous of these components is the ( most recent articles ) component.
Once you insert the component into the article or page you are editing, the settings box for the component will appear in front of you, in which you will find many options to control the appearance and display of articles:
As you can see, you can control the way the box (the latest articles on the site) is displayed , such as the ability to display the content of the article or just the title. You also find options for displaying the name of the writer, the date of publication, or displaying the featured image of the article, as well as the order from oldest to newest, or vice versa.
3. Show the most popular articles using code
In this part, we will explain to you another way to display the most popular articles on your site without using WordPress plugins. In this method, we will rely on adding code manually by modifying the code files of the WordPress template used on your site.
To apply this method, you must have the ability to modify the WordPress source code and have good knowledge of the PHP language. Of course, we always advise you to take a backup copy of your WordPress site before modifying the source code.
In order to display the most popular or most visited articles within your site, you must first add code into the functions.php file of the WordPress theme currently used on your site.
Copy and paste the following code before the closing tag <? In the file, in order to calculate the number of visits that the site’s articles receive.
The code above is a programming function written in the PHP language and it is called setPostViews. In this function, the value of a custom field in WordPress was used, which is the field post_views_count, which is a meta key that stores the number of visits or views of each article on the site.
After adding the code into the functions.php file of the template and saving the changes you made, the file will be as follows:
After placing the previous code in the functions.php file, now go to the single.php file, which is one of the template files in WordPress for formatting posts. Search in this file for the following loop instruction:
After finding it, paste the following code directly after the while statement:
The file will be as follows:
The function of this code is to call the software function that we knew inside the functions.php file in the previous step, which counts for us the number of visits that enter any article on the site by passing the parameter or the actual parameter to it, which is the article ID (which we obtain through the function get_the_ID). . Therefore, we will have an integrated function that can calculate the number of visits within each article on the site.
The final step now is to show the most popular articles within the site by adding the following code inside the template file for the part in which you want to display the articles. For example, you can paste it inside the template file footer.php so that the most popular articles are displayed inside the site’s footer.
After adding the code into the footer.php file, it will be as follows:
After that, you can click on the (Save Changes) button for the software file, and then go to your site to notice that the most popular articles appear as follows in the site footer:
Note : The number of visits will be counted and the most popular articles will be determined starting from the moment the codes are pasted into the WordPress files.
Conclusion
In the end, showing the most popular or most viewed articles on your site is a simple matter that gives visitors more interaction with your site’s content.
Therefore, take care to display these articles within the content of your site in order to increase visitor interaction with the site content, as the visitor always prefers to see popular articles that have interesting content from site visitors
Leave a Reply