3

How can I achieve loop pagination? Lets say I have 5 articles, Im adding pagination and on the 1-st page I have "next" button, on pages 2-4 I have both "next" and "prev" buttons, on the last 5-th page I will have only "prev" button. How Can I have "next" and "prev" buttons both on every page? So after reaching 5-th page and pressing "next" Im going to 1-st page, like loop or circle.

2

The article pagination is handled by a content plugin called pagenavigation, located in ROOT/plugins/content/pagenavigation. The problem is that although Joomla allows for plugin overrides, most plugins don't support it, including this particular plugin. Either way, the code you have to change is in pagenavigation.php in the aforementioned folder (at aprox. line #174):

Change the existing code:

        if ($location - 1 >= 0)
        {
            // The previous content item cannot be in the array position -1.
            $row->prev = $rows[$location - 1];
        }

        if (($location + 1) < count($rows))
        {
            // The next content item cannot be in an array position greater than the number of array postions.
            $row->next = $rows[$location + 1];
        }

With this:

        if ($location - 1 >= 0)
        {
            // The previous content item cannot be in the array position -1.
            $row->prev = $rows[$location - 1];
        } else {
            // Add button to return to last element
            $row->prev = $rows[count($rows)-1];
        }

        if (($location + 1) < count($rows))
        {
            // The next content item cannot be in an array position greater than the number of array postions.
            $row->next = $rows[$location + 1];
        } else {
            // Add button to return to start
            $row->next = $rows[0];
        }

As far as I know, you have three ways to solve this:

  1. Edit the original file, as above. This is called a core hack, and not recommended, because your edits might be overwritten when you update Joomla.
  2. Create a new plugin based on the existing plg_pagenavigation, and apply the edits. Then publish your new plugin and unpublish pagenavigation.
  3. Make the plugin compatible with plugin overrides by adding this code to ROOT/plugins/content/pagenavigation/pagenavigation.php, right after defined('_JEXEC') or die;:

    $chromePath = JPATH_THEMES . '/' . JFactory::getApplication()->getTemplate() . '/html/pagenavigation.php';
    if (file_exists($chromePath))
    require_once ($chromePath);
    
    if (!function_exists('plgContentNavigation')) {
      function plgContentNavigation( &$row, &$params, $page=0 )
      {
    

    Then this at the end of the file:

     }
    }
    

    This will make Joomla look for the file ROOT/templates/YOURTEMPLATE/html/pagenavigation.php and use it as override if it exists. It's still a core hack, but it might be easier to maintain.

  • Yes, it is working! Thank you so much for helping me out. Cheers – be well Oct 7 '14 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.