TYPO3 menu sorting

From snippet wiki
Jump to navigation Jump to search

If you have a sidebar menu which displays pages from multiple nodes, those pages will stay sorted by node. First the sorting from source ID 101, then the next sorted batch from ID 102.

As this isn't what you might want, call an itemArrayProcFunc you store on your server.

lib.menuleft = HMENU
lib.menuleft.special = directory
lib.menuleft.special.value = 101,102
lib.menuleft {
  stdWrap.wrap = <nav id="sidebarleft"><ul class="vertmenu ml1">|</ul></nav>
  1 = TMENU
  1 {
    noBlur = 1
    NO.wrapItemAndSub = <li>|</li>
    NO.ATagParams = class="normal"
    NO.stdWrap.htmlSpecialChars = 1
    ACT < NO
    ACT.wrapItemAndSub = <li class="current">|</li>
    ACT.ATagParams = class="current"
    ACT.doNotLinkIt = 0
    ACT = 1
    itemArrayProcFunc = user_sortMenu
  }
}

Within /fileadmin/lib/sortmenu.php:

<?php

function user_pageCmp($page1, $page2) {
        $page1SortField = trim($page1["nav_title"]) == "" ? "title" : "nav_title";
        $page2SortField = trim($page2["nav_title"]) == "" ? "title" : "nav_title";

        $ret =  strcasecmp  ( utf8_decode( $page1[$page1SortField] ) , utf8_decode( $page2[$page2SortField] ) );

        return $ret;
}

function user_sortMenu($menuArr) {
        usort($menuArr, "user_pageCmp");
        return $menuArr;
}

And define that new php file within typo3conf/localconf.php:

require_once(PATH_site . "/fileadmin/lib/sortmenu.php");