Change default order of weblinks

 It took a few google searches until I could find out how to change the default weblinks order.  A lot of websites showed how to do this via the admin back-end panel in the advanced configuration... I can't see this panel, there is no advanced parameters under a weblinks category.

The issue is that suppose a menuitem links to a category of weblinks, the default sort order (as in the first time you view the page) is the order in the admin panel (not even by most recent).  I'm going to show you how to do this by title in ascending order without installing any 3rd-party extension as well as by any of the database values used by each link.

Joomla 1.5.x

I found the page to edit after going through the Joomla forums for a bit. Their solution only permanently sets the default sort order to WEBLINK TITLE in order from A to Z. The below code with my modifications maintains the functionality for the user to change the sort order by clicking on the column titles.

The page you want is /components/com_weblinks/models/category.php and you are going to edit the _buildQuery() function, search the file for the following comment and text. As always, I would recommend you make a copy of the file before making the change just in case you need to revert the change:

// We need to get a list of all weblinks in the given category
$query = 'SELECT *' .
	' FROM #__weblinks' .
	' WHERE catid = '. (int) $this->_id.
	' AND published = 1' .
	' AND archived = 0';
$query.=($filter_order!="ordering")?' ORDER BY '. $filter_order .' '. $filter_order_dir .', ordering':' ORDER BY title ASC';
  1.  // We need to get a list of all weblinks in the given category 
  2.  $query = 'SELECT *' . 
  3.      ' FROM #__weblinks' . 
  4.      ' WHERE catid = '(int) $this->_id. 
  5.      ' AND published = 1' . 
  6.      ' AND archived = 0'
  7.  $query.=($filter_order!="ordering")?' ORDER BY '$filter_order .' '$filter_order_dir .', ordering':' ORDER BY title ASC'


To sort by another value on page load

To do this, change the word 'title' in the above code to one of the following values:

    id => sort by ID
    catid => sort by Category ID
    sid => ? dunno
    title => by web link title
    alias => sort by alias title
    url => sort by url
    description => sort by description
    date => sort by date added (most recent or oldest first)
    hits => sort by hits (number of times clicked on)
    published => obviously by whether they're published or not... no idea why u would
    checked_out => sort by checked out (will either display or not on the front page so again not any use to sort by this)
    checked_out_time => just cos this value exists, don't know why you would order by this
    ordering => the setting it's on if you haven't made this modification. I don't like it and nor do u if you've been trawling the web for this solution.
    archived => is or not
    approved => again
    params => what params? I couldn't find any

A little more

to change A-Z or Z-A change ASC (ascending) to DESC (descending) in the last bit of the above code.

To sort by 2 categories, change ' ORDER BY title ASC' to 'ORDER BY title ASC, hits DESC' where 'title' is the first and 'hits' in descending (so most hit first)

For specific categories

For my website, I've shoved all my links into one page because I didn't like how weblink categories display on the weblinks page. I could modify the page for categories (by default it's an ugly unordered list), but changing scripts gets overwritten in a joomla upgrade so too many changes is a hard process to keep track of.

Joomla 1.6.x

Responding to a comment by J16 User (9 July 2011): As an update for those of us brave enough to use the upgraded CMS, I have looked into this and it would appear that Joomla! CMS have not changed this. I'd imagine it quite low priority.

This is easier to tweak in the upgrade. The following will again maintain the functionality for your website visitors to change the order. If you want to change the default order of your weblinks in the front-end of your Joomla! website, you will need to modify the following file: /components/com_weblinks/models/category.php (make a backup/copy first)

Look for the following line of code [the function is "protected function populateState("]:
Line 181:	$orderCol	= JRequest::getCmd('filter_order', 'ordering');
  1.  Line 181:    $orderCol    = JRequest::getCmd('filter_order', 'ordering')
and change this to:
$orderCol	= JRequest::getCmd('filter_order', 'title');
  1.  $orderCol    = JRequest::getCmd('filter_order', 'title')
Now I've ordered my weblinks by title in this example, but here are some others that may be of interest (simply replace the word title with one of the bolded words below):
  • id     -   by weblink identifying number
  • catid     -   by category identifying number
  • title     -   by weblink title
  • alias     -   by its alias - same as weblink title only without crazy symbols
  • url     -   could be an issue if some of your links have http and some don't
  • description     -   not recommended!
  • date     -   the one I use for most recent
  • created     -   this is also a date formatted field
  • modified     -   and this is a date formatted field
  • hits     -   number of times that weblink has been visited
  • state     -   this is the J16 published/unpublished status
  • ordering
  • featured
To switch the default ordering (ascending / descending), change the ASC to DESC on line 187:
$listOrder	=  JRequest::getCmd('filter_order_Dir', 'ASC');
  1.  $listOrder    =  JRequest::getCmd('filter_order_Dir', 'ASC')
Note: If you do not use any of these or mistype them, the Joomla! CMS has included code so that weblinks automatically switch to "ordering".
Category: Joomla :: Article: 228

Credit where Credit is Due:

Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman

Related Articles

Joes Revolver Map

Joes Word Cloud


Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Donate to Joel Lipman via PayPal

Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF
© 2024 Joel Lipman .com. All Rights Reserved.