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:

copyraw
// 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("]:
copyraw
Line 181:	$orderCol	= JRequest::getCmd('filter_order', 'ordering');
  1.  Line 181:    $orderCol    = JRequest::getCmd('filter_order', 'ordering')
and change this to:
copyraw
$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:
copyraw
$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

Comments

Not rated
Didszzz
0
Didszzz
12 years ago
Ive changed my php file but its not changing anything on the web links!

Can anyone help me out plz

Im using Joomla! 2.5.8

this is the code i changed!

$orderCol = JRequest::getCmd('filter_order', 'date');
if (!in_array($orderCol, $this->filter_fields)) {
$orderCol = 'ordering';
Like Like
Reply | Reply with quote | Quote
View replies
WebmasterLegacy
0
WebmasterLegacy
12 years ago
Hi Didszzz,

It looks like you're overwriting all your hard work by setting Code:$orderCol='ordering'

You could just set it to what you want as default. Note that the function it is contained within is when the user clicks on a column heading to re-order them.

Hope that helps!
Like Like
Reply | Reply with quote | Quote
View replies
Didszzz
0
Didszzz
12 years ago
Quoting Joel Lipman:
Hi Didszzz,

It looks like you're overwriting all your hard work by setting Code:$orderCol='ordering'

You could just set it to what you want as default. Note that the function it is contained within is when the user clicks on a column heading to re-order them.

Hope that helps!



Thanks for that help! I changed the JRequest::getCmd('filter_order_Dir', 'ASC');

to JRequest::getCmd('filter_order_Dir', 'DESC');
and this did the trick :-) all is working now thank you for input on this!
Like Like
Reply | Reply with quote | Quote
J! 1.6 user
0
J! 1.6 user
14 years ago
hmmmm... looks great BUT... kinda different in J! 1.6

wish it WAS that easy... maybe an update would be nice 8) :-*
Like Like
Reply | Reply with quote | Quote
View replies
WebmasterLegacy
1
WebmasterLegacy
14 years ago
Hi J16 User,

Thanks for your message. I'd initially dismissed this as I thought Joomla! had fixed this but no they still prefer to default the order to 'ordering'.

Fortunately, I've found the fix to be even easier than in J15. Another hard-code unfortunately.

Open the file /components/com_weblinks/models/category.php

Look for the line :
Code:$orderCol = JRequest::getCmd('filter_order', 'ordering');


change this to:
Code:$orderCol = JRequest::getCmd('filter_order', 'title');
Like Like
Reply | Reply with quote | Quote
TIPS TRIK GRATIS
1
TIPS TRIK GRATIS
14 years ago
thanks my friend
Like Like
Reply | Reply with quote | Quote
Favatron3
0
Favatron3
15 years ago
tytytytyty!
Like Like
Reply | Reply with quote | Quote

Add comment

Your rating:

Submit

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
www.joellipman.com

Accreditation

Badge - Zoho Creator Certified Developer Associate
Badge - Zoho Deluge Certified Developer
Badge - Certified Zoho CRM Developer

Donate & Support

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

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF

Please publish modules in offcanvas position.