I have a third party component which uses joomla's pagination system. How can I change the values of default items per page and limit box values for the front-end only, without changing anything in the back-end?
For J2.5 :
You can change the value form configuration.php directly:
public $list_limit = '20'; TO public $list_limit = '4'; for example.
-> But the problem is that when you will save any parametre on the backend, you will lose your config, so you need to change it angain and againt. (so it is not the best solution)
The best solution is to go to :
/administrator/components/com_config/models/forms/application.xml
Search for the field name="list_limit"
you will find the default configuration of joomla! on line 661 :
<field
name="list_limit"
type="list"
default="20"
label="COM_CONFIG_FIELD_DEFAULT_LIST_LIMIT_LABEL"
description="COM_CONFIG_FIELD_DEFAULT_LIST_LIMIT_DESC"
filter="integer">
<option
value="5">J5</option>
<option
value="10">J10</option>
<option
value="15">J15</option>
<option
value="20">J20</option>
<option
value="25">J25</option>
<option
value="30">J30</option>
<option
value="50">J50</option>
<option
value="100">J100</option>
</field>
ADD an option like :
<option value="3">J3</option>
it become :
<field
name="list_limit"
type="list"
default="20"
label="COM_CONFIG_FIELD_DEFAULT_LIST_LIMIT_LABEL"
description="COM_CONFIG_FIELD_DEFAULT_LIST_LIMIT_DESC"
filter="integer">
<option
value="3">J3</option>
<option
value="5">J5</option>
<option
value="10">J10</option>
<option
value="15">J15</option>
<option
value="20">J20</option>
<option
value="25">J25</option>
<option
value="30">J30</option>
<option
value="50">J50</option>
<option
value="100">J100</option>
</field>
Have a look at the docs for Joomla pagination:
http://docs.joomla.org/Using_JPagination_in_your_component
You will need to find a vaiable that looks like:
$limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
It could be called $lim, $limit or anything else that the developer thinks is appropriate. It is usually found in the model, but it can be in the view. You need to change this variable to something like:
$limit = 20;
Where 20 is the value for the limit you would like to set.
This complements seavers answer, which in my opinion is the correct answer.
I will code an example of how I limited the number of pages that I wanted displayed in the search's results page:
From a template file root/templates/mytemplate/html/com_search/search/default.php
// number of max pages you want in pagination
$mylimit = 3;
// to prevent showing pages with no resutls
$limit = min($mylimit, $this->pagination->pagesTotal);
// set the limit
$this->pagination->pagesStop = $limit;
RENDERS:
In several of our components we have created a pagination extension to override the default options, which are hard coded and cannot be overwritten otherwise.
class myCompPagination extends JPagination {
public function getLimitBox() {
.. Your Custom Renderer ..
}
}
The base class is found under /libraries/cms/pagination in Joomla 2.5 and higher.
Include your custom class and use it just like you would otherwise. $pagination = new wbCompPagination( ... );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With