I have created a website based on Joomla. I have many items in my Main-Left menu, which all link to "Category blog layout"s, which shows a bunch of articles in every category.

I need to create a Next/previous for every menu item, so every time someone is in menu item 3 and presses Next comes into item 4 and so on.

So in short, what I need is pagination for my menu items and not just articles. Hope you guys can help.

  • what did you tried? can you provide us with some code / screenshots? which version of joomla?
    – Josip Ivic
    Oct 10, 2015 at 9:50
  • I havent Tried much. I dont know Where to start, but my menu navigation is easy. Its like menu item one is numbered 1. Like site.com/1 and site.com/2 etc up to 100. Im using the latest joomla 3.X
    – Peter
    Oct 10, 2015 at 13:57
  • You want the next/previous button in the category blog page or in the menu block?
    – webchun
    Oct 12, 2015 at 16:31
  • I want it in the category blog page pleas. Or in a separate module Where ever i want to.
    – Peter
    Oct 12, 2015 at 20:41
  • You need to write a function to query the link and id fields from #__menu in your database where the menu type is the menu type of your current menu item. You can get the menu type by querying that field in the database and filter by your current Itemid. From there it would take some tweaking the array that gets return so that the order is in the same order as your menu items. Use JRoute with the data returned from the link field and the Itemid and voila, a working menu item pagination.
    – Terry Carter
    Feb 6, 2016 at 3:46

1 Answer 1


Download Flexi Custom Code Module from the JED and install it. Publish the module to whatever position on the page you want. Hide the module title. Disable clean css, clean, html and clean jscript. Leave PHP turned on

Enter this code in the custom code box

$menu = JFactory::getApplication()->getMenu();
$JInput = JFactory::getApplication()->input;
$Itemid = $JInput->get('Itemid','','int');
$items = $menu->getMenu();

$pagination = array();
foreach($items as $item){
    if($item->link != '' && $item->type != 'separator' && $item->level == 1){
        if(strpos($item->link, 'index.php?option')!== false){
            $link = JRoute::_($item->link.'&Itemid='.$item->id);
            $link = $item->link;
        $pagination[] = array('Itemid'=>$item->id, 'link' => $link);

foreach($pagination as $k => $menuItem){
    if($menuItem['Itemid'] == $Itemid){
        if($k == 0){
            $prev = $pagination[count($pagination) - 1]['link'];
            $next = $pagination[$k + 1]['link'];
        }elseif($k == count($pagination) - 1){
            $prev = $pagination[count($pagination) - 2]['link'];
            $next = $pagination[0]['link'];
            $prev = $pagination[$k - 1]['link'];
            $next = $pagination[$k + 1]['link'];

echo $next.'<br />'.$prev;

echo '<pre>';
echo '</pre>';

This code assumes that all of your menu items are root level menu items and that they are not Text Separators. The pagination should automatically update based on what page you are on and if you change the sort order of menu items in the backend.

I only briefly tested this on my site and it works. You may need to tweak it a little bit but it should be a good place to start at least.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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