In this article we are going to build out a most popular post section for Oxygen Builder. The Oxygen Builder repeater element as well as the easy posts element both come with advanced query features, and with just a little bit of work, you can easily display the most popular posts by page views for a WordPress website.
To do this, we are going to need a third party plugin, but it's freely available from the WordPress repository, fairly lightweight, and a great addition for any content website using this CMS.
Grab WP-PostViews and install it on your Oxygen Builder website. This plugin tracks the number of views that each post gets and stores that information in your database, meaning that you can easily query posts by their popularity. Keep in mind, that there is a built in popularity query using the oxygen builder, but this uses the comment count, and not the post view count.
This plugin isn't meant to be an analytics solution, and is very simple. Essentially, you install it and it automatically begins tracking the number of page views per post.
Once you've installed the plugin, it's time to build out your query. This is a very simple and easy process, all you need to do is copy and paste this code into the manual section of the query tab under the easy posts or repeater element in Oxygen.
Build out your query by using any of the standard WordPress terms. to order by popularity, you simply need to add this line (with the post views plugin enabled)
orderby=meta_value&meta_key=views
Here's an example query that we use on our website:
posts_per_page=5&post_type=post&no_found_rows=true&post_count=5&found_posts=5&order=DESC&orderby=meta_value&meta_key=views
Code language: JavaScript (javascript)
What this does is order the posts by the number of views associated with it. if you're looking to build out a most popular posts feature in oxygen builder, this is by far the best way to do it. if you have any questions don't hesitate to reach out via our comments section, and we hope that this was a beneficial article!
Hi, the images is unavailable. Could you please update them?
Hi James!
Thanks for the tutorial.
Do you know how to make it work with a custom post type in a taxonomy archives page?
I've changed the "&post_type=post" for "&post_type=my_cpt_name" but it doesn't work.
Is it possible that I need to specify the taxonomy, as well? I want it to set up as a template that works for every taxonomy term in my custom post type.
Do you have any idea how to achieve that?
Thanks!
Isaura - I love your agency and website!!
I'm actually about to implement this on a site of mine today. I'll check back if/when I figure this one out. You may want to actually use the advanced query builder that shipped w/ 3.8, it may make life easier!
Thank you very much, James!! 🙂 Yes, I replicate your "manual" code as an Advance Query of the Repeater, but I don't know WP_query or PHP, so I am not able to customize it to suit my needs!
How would you do it via the Advanced Query Builder? We implemented it on the site but it is random in showing which one has the most views. Generally speaking, it is not accurate.