PortuguêsEnglish (United Kingdom)

k2 order User items in blog view

Rate this item
(4 votes)
K2 component for Joomla K2 component for Joomla

Quick-fix to the lack of ordering options in the User Blog items list.

 

After searching everywhere in the K2 component settings, I found that there weren't any option that made any kind of sorting, to the items in the user blog.

The next step was to search the Internet if it was a bug and if there was a "quick-fix". In the K2 website there are some forum threads reporting this same problem but no solutions.

Then I went into the code. I found the line of code that creates the SQL query (this file has the construction of queries for all other item listings ) and i quickly realized that this particular listing had no ordering.

Solution

In order to sort the items, we have to edit the file named "itemlist.php" located in "components/com_k2/models".

Line 100, wich has "case 'user':", is the line that creates the part concerning the listing of items per user.

Therefore, after the line 102 that contains "$query .= " AND i.created_by={$id} AND i.created_by_alias=''";", insert the following line of code:

$ordering ='rdate';

Where rdate can be changed by one of the following:

  • The default is sorted by the id of the item
  • 'date' -> creation date ascending
  • 'rdate' -> reverse the previous
  • 'alpha' -> alphabetical order of title
  • 'order' -> the order specified in the listing of items in k2 administrator
  • 'rorder' -> reverse the previous
  • 'hits' -> by most views
  • 'rand' -> random
  • 'best' -> by rating given by users

 

Now just save it and update the web page. I hope this helps.

Latest from Megaklique

Latest works

Latest News