Guys im in need of a way to sort my posts by views, rating, comments. ive search loads of plugings but their all buggy.
i want something like this.
sorting http://img138.imageshack.us/img138/2577/sorting.png
Guys im in need of a way to sort my posts by views, rating, comments. ive search loads of plugings but their all buggy.
i want something like this.
sorting http://img138.imageshack.us/img138/2577/sorting.png
You must be logged in to post a comment.
For separating the different ways of sorting you could use something like jQuery to create a tabbed area, within each you call a different (php) function to sort your posts accordingly and then define these php functions in your function.php file.
As for the functions – wordpress already stores the number of comments on a post -but you’ll need to get it store page view / ratings. For the first, wp-postviews will work fine – we just want something to store the data. It comes with dedicated functions to get posts by popularity which you could use, but in case you wanted greater flexibility I’ve included functions below which sort by number of views or number of comments:
For sorting by comments:
For sorting by post views
Then just include those functions:
get_most_visited()
andget_most_commented()
(with an optional argument of number of posts – default is 10) inside<ul>
or<ol>
tags. (I’ve included how to retrieve the number of comments/views in case you wanted to use them – otherwise you could remove them)This method gives you a lot of flexibility in how to present the posts. Basically – this allows you easily to style the list with some basic CSS styling or something a bit fancier involving jQuery.
As for post ratings a plugin like Post Star Ratings might do the trick to store ratings, and then you could use a similar function to the above.
Hope this helps!
You’re going to have to write your own custom queries in WordPress. This involves getting comfortable with PHP and some WordPress API.
A good starting point: http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query
As for the ways you want to sort, you’ll first need to capture views and ratings. My intuition says you can store everything in custom fields–so familiarize yourself with the post_meta table. Here are some thoughts off the top of my head:
Most Viewed: In your single.php, everytime a post is loaded, make sure you add a custom field that increments – use this custom field in your ORDER BY query.