2

I'm using Joomla 2.5 and K2 2.5.7. I have a category with posts with a different number of votes. In the front end, I need to sort the items of this category by number of votes.

I re-configured standard stars rating systems to simple "Give one vote" system.

I need this for a ranking order page, so it will have items with the largest number of votes on the top.

What I have

I have my MVC template for K2 category. I was wondering, if sorting $this->leading in category.php is the right to go for.

If it is, how can I do it? With var_dump there is variable numOfVotes which carry real number of votes. How can I sort this object by this var?

Thank you very much!

4

1 回答 1

1

This K2 forum post seems to answer your question. You need to use the mod_content k2 module and use the "sort by" parameter and select highest rating.

If you go to 'modules/mod_k2_content/helper.php' in the ftp, you'll see on line 98, that there it says

$query .= ", (r.rating_sum/r.rating_count) AS rating";

This sorts the data by the highest rating. Now generally this would sort it by the number of votes divided by the number of people who have voted giving a result between 1 and 5. However as everyone in your case gets a vote of 5 - then your average result will always be 5 by that calculation!, I think that you'll have to replace that line with:

$query .= ", r.rating_count AS rating";

i.e. just sorting by the number of people who have voted (N.B. This assumes you're not using a vote down system as well! You haven't mentioned it so I'm assuming not)

Then you should just be able to use the module (selecting the parameter that you desire as normal)

For using the component category option etc. Then the same line of code can be found in 'components/com_k2/models/itemlist.php' on Line 39 which again would need to be edited. Then you could just use the built in parameters as usual!

于 2012-09-13T12:49:59.283 回答