Default search result to 5 records per page?

General questions relating to Joomla! 2.5. Note: All 1.6 and 1.7 releases have reached end of life and should be updated to 2.5. There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Locked
sim085
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 194
Joined: Mon Oct 04, 2010 4:11 pm

Default search result to 5 records per page?

Post by sim085 » Fri Sep 09, 2011 9:21 pm

Hello, I was wondering if it is possible to change the default number of results shown on the search page from 20 to for example 5.
Last edited by sim085 on Sun Sep 11, 2011 10:47 am, edited 1 time in total.

User avatar
jmuehleisen
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4874
Joined: Thu Nov 09, 2006 2:46 pm
Location: Kampala, Uganda
Contact:

Re: Default search result to 5 records per page?

Post by jmuehleisen » Sun Sep 11, 2011 6:26 am

Joomla gets the "how many records per page" from the "list size" as defined in your global configuration.

The default, as you note, is 20.

You can change it there to 5.

The problem is that this list length applies everywhere in Joomla, including in your site administrator.

Not good (for most of us).

So, your next option is to modify the com_search component to use 5 instead of the default list length.

The code that defines the list length for search results is in this file:

Code: Select all

/components/com_search/models/search.php
Around line 65 you will see something like this:

Code: Select all

// Get the pagination request variables
	$this->setState('limit', $app->getUserStateFromRequest('com_search.limit', 'limit', $config->get('list_limit'), 'int'));
That line of code says "get the list limit length from the configuration file and use it here."

You can change that line to read like this:

Code: Select all

// Get the pagination request variables
	$this->setState('limit', $app->getUserStateFromRequest('com_search.limit', 'limit', 5, 'int'));
That will put a "hard coded" default search results limit of 5 by replacing "$config->get('list_limit')" with the number 5 (or whatever you want).

(Be sure to backup this file before editing in case you make a big mistake and also save your edits back up to your server after editing).

Now the problem with this approach is that you are "hacking the Joomla core."

Which is fine ... you can do that.

But, when you do a Joomla update there is a possibility that these edits to the core file may be overwritten and you will have to go in and modify it again.

Joomla provides a way to preserve your edits to the output of these components (in the html folder of the component) through "template overrides", but I don't know of a way to preserve the edits to a "model" file.

Perhaps someone else can help us on that one.

But, this would get the results that you want, with the limitation that it may or may not survive a Joomla update.
John Muehleisen
Visit my "Getting Started with Joomla" site, now with videos, tips, and new user tutorials:  http://welcometojoomla.com

sim085
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 194
Joined: Mon Oct 04, 2010 4:11 pm

Re: Default search result to 5 records per page?

Post by sim085 » Sun Sep 11, 2011 11:33 am

Thanks for the very detailed reply. your reply was very helpfull!!


Locked

Return to “General Questions/New to Joomla! 2.5”