Joomla Sitemap Anzeige Script / Menü auslesen / getMenu

Gepostet am April 3, 2013

Folgend möchte ich ein Script zeigen, welches ein Menü von Joomla ausliest und dieses als Sitemap darstellt.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<h1>Sitemap</h1>
<?php
if ($lang=="de-DE") $menuId = 0;
else $menuId = 1;
 
$menu = JFactory::getApplication()->getMenu();
$items = $menu->getItems($menuId,0);
 
$arrayMenu = '';
foreach ($items as $item) {
    $level = count($item->tree);
    if ($level==1) {
        $arrayMenu[$item->tree[0]]['Title'] = $item->title;
        $arrayMenu[$item->tree[0]]['Alias'] = $item->alias;
    }
    if ($level==2) {
        $arrayMenu[$item->tree[0]]['Submenu'][$item->tree[1]]['Title'] = $item->title;
        $arrayMenu[$item->tree[0]]['Submenu'][$item->tree[1]]['Alias'] = $item->alias;
    }
    if ($level==3) {
        $arrayMenu[$item->tree[0]]['Submenu'][$item->tree[1]]['Submenu'][$item->tree[2]]['Title'] = $item->title;
        $arrayMenu[$item->tree[0]]['Submenu'][$item->tree[1]]['Submenu'][$item->tree[2]]['Alias'] = $item->alias;
    }
}
 
//Output
foreach ($arrayMenu as $mId => $mItem) {
    echo '<a href="/'.$mItem['Alias'].'">'.$mItem['Title'].'</a><br/>';
    if (isset($mItem['Submenu'])) {
        foreach ($mItem['Submenu'] as $smId1 => $smItem1) {
            echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/'.$mItem['Alias'].'/'.$smItem1['Alias'].'">'.$smItem1['Title'].'</a><br/>';
            if (isset($smItem1['Submenu'])) {
                foreach ($smItem1['Submenu'] as $smId2 => $smItem2) {
                    echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/'.$mItem['Alias'].'/'.$smItem1['Alias'].'/'.$smItem2['Alias'].'">'.$smItem2['Title'].'</a><br/>';
                }
            }
        }
    }
    echo "<br/>";
}
?>

Tags: ,

Leave a Reply

 

Posts of Current Category



Facebook: