How to implement pagination in joomla?

I am using pagination in joomla. Below is the code

      $db = JFactory::getDbo();
      $query = $db->getQuery(true)
                        ->select('c.*,cat.alias as catalias')
                        ->from('#__content AS c')
                        ->from('#__categories AS cat')
                        ->where('c.catid=19','AND')
                        ->where('c.state=1','AND')
                        ->where('c.catid = cat.id')
                        ->order('c.created '.' ASC');

    $db->setQuery($query,0,5);
    $results = $db->loadAssocList();
    $db->setQuery('SELECT FOUND_ROWS();');
    jimport('joomla.html.pagination');
    $pager= new JPagination($db->loadResult(), 0, 2);

    foreach ($results as $res) {  
    echo $res['id'];
    ....
    .....
    }

    echo $pager->getListFooter();

      

This displays the page numbers in the footer (for example 1 2 3 with hyperlinks) based on the page limit (6 records on 3 pages (page limit 2)). But all records are displayed on one page. Not like two entries on each page.

What changes are needed here. Please help me everyone.

Thank you in advance

+3


source to share


2 answers


I got a solution for my question:



    $db = JFactory::getDbo();
    $app = JFactory::getApplication();
    $limit = $app->getUserStateFromRequest("$option.limit", 'limit', 2, 'int');
    $limitstart = $app->input->get('limitstart', 0, 'INT');
    $query = $db->getQuery(true)
             ->select('SQL_CALC_FOUND_ROWS c.*,cat.alias as catalias')
             ->from('#__content AS c')
             ->from('#__categories AS cat')
             ->where('c.catid=19','AND')
             ->where('c.state=1','AND')
             ->where('c.catid = cat.id')
             ->order('c.created '.' ASC');

    $db->setQuery($query,$limitstart, $limit);
    $results = $db->loadAssocList();
    if(!empty($results)){
        $db->setQuery('SELECT FOUND_ROWS();');
        jimport('joomla.html.pagination');
        $pager= new JPagination($db->loadResult(), $limitstart, $limit);

        foreach ($results as $res) {  
            echo $res['id'];
            YOUR_CODE_HERE
        }

        echo $pager->getListFooter();
   }

      

+2


source


If you want to change the default article breakdown, you must override the default template for the page content plugin.



0


source







All Articles