The following warnings occurred:
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/printthread.php 203 postParser->parse_message
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/printthread.php 203 postParser->parse_message
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/printthread.php 203 postParser->parse_message
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/printthread.php 203 postParser->parse_message
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/printthread.php 203 postParser->parse_message
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/printthread.php 203 postParser->parse_message
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/printthread.php 203 postParser->parse_message
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/printthread.php 203 postParser->parse_message



GetSimple Support Forum
Simple Tree Multi-level Menu (quick hack) - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: Scripts & Components (http://get-simple.info/forums/forumdisplay.php?fid=11)
+--- Thread: Simple Tree Multi-level Menu (quick hack) (/showthread.php?tid=565)



Simple Tree Multi-level Menu (quick hack) - Carlos - 2010-03-21

A quick-and-dirty function to display multi-level menus.

Edit: it will not work on GetSimple versions before 2.01 (thanks Zegnåt)

Edit again: bugfix 1.1

1. Create a text file (e.g. menu1.txt) like this:
Code:
page-slug
#subpage-slug
##subsubpage-slug
###subsubsubpage-slug
No slug, text label
#another-subpage-slug
... Upload it to data/other

2. In your theme's functions.php (create it if does not exist) insert this function:
Code:
// Simple Tree Menu v1.1 by Carlos Navarro
function simple_tree_menu($menufilename){
        $menufile = file('data/other/'.$menufilename);
        $prevlevel = -1;
        foreach ($menufile as $thisline) {
            if (trim($thisline) != '') {
                $thislevel = substr_count($thisline,'#');
                $thisline = trim( str_replace('#','',$thisline) );
                $diff=$thislevel - $prevlevel;
                if ($diff == 1)
                    echo '<ul class="menulevel-'.$thislevel.'"><li>';
                else
                    if ($diff < 0) {
                        while ($diff < 0) {
                            echo '</li></ul>';
                            $diff++;
                        }
                    }                
                if ($diff==0)
                    echo '</li><li>';
                if (file_exists('data/pages/'.$thisline.'.xml')) {
                    $thisfile = @file_get_contents('data/pages/'.$thisline.'.xml');
                    $data = simplexml_load_string($thisfile);
                    if ($data->menu != '')
                        $thistitle = $data->menu; // display menu text if present
                    else
                        $thistitle = $data->title; // if not, display page title
                    echo '<a href="'.find_url($data->url,$data->parent).'">'.$thistitle.'</a>';
                }
                else {
                    echo $thisline; // if page doesn't exist, display string
                }
                $prevlevel = $thislevel;
            }
        }
        for( $i=0; $i <= $thislevel; $i++) echo '</li></ul>';
}

?>

3. In your theme's template.php (e.g. in the sidebar) insert this code:
Code:
<?php simple_tree_menu('menu1.txt'); ?>

That's it. Suggestions and corrections welcome.

Demo here

PS could be better to use a Component instead of text files, however this way you are able to include several different menus.


Simple Tree Multi-level Menu (quick hack) - Zegnåt - 2010-03-21

This will save those who wish to hand code there menus a lot of time by making the progress lots easier. I still don’t think it can beat an actually generated menu though.

Just for the record, it will not work on GetSimple versions before 2.01.


Simple Tree Multi-level Menu (quick hack) - Carlos - 2010-03-22

Zegnåt Wrote:I still don’t think it can beat an actually generated menu though.

Agreed, but as long as GS doesn't support more than two levels, you have to do some trick if you need a 3rd or 4rd one (and still want to use GetSimple ;-))

Quote:Just for the record, it will not work on GetSimple versions before 2.01.

Thank you, post edited.
An example of any function I used that's not supported by 2.0 or 1.x...?


Simple Tree Multi-level Menu (quick hack) - Zegnåt - 2010-03-22

find_url() is very new and was not defined until 2.01.

Eg: my menu plugin (the version that is currently being beta tested) ships with an extra file to ensure backwards compatibility by defining find_url if it doesn’t exist.


Simple Tree Multi-level Menu (quick hack) - Carlos - 2010-03-22

I found a bug in the function, it didn't close the lists properly if last line is not a first level page.

Replaced:
Code:
echo '</li></ul>';
with:
Code:
for( $i=0; $i <= $thislevel; $i++) echo '</li></ul>';

I have just edited the function (now v1.1). Sorry.


Simple Tree Multi-level Menu (quick hack) - homershines - 2010-04-22

Can page anchors also be added to these menus?
I have a directory project, where each page contains multiple articles within a specific category.
I want to have category anchors as a menu option for each page in the directory.
Sort of like this...

Foods
#Fruits Page
##Grapes Article
##Melons Article
##Oranges Article

Is that possible?

Thanks.

homershines


Simple Tree Multi-level Menu (quick hack) - Carlos - 2010-04-22

Sorry, this script does not support slugs with anchors, as is.

Only thing I can think may be done is inserting html code just like text labels. You could do something like:

Foods
$fruits
$$<a href="fruits/#Grapes Article">Grapes</a>
$$<a href="fruits/#Melons Article">Melons</a>
$$<a href="fruits/#Oranges Article">Oranges</a>

In the function, on both lines 6 and 7, '#' should be changed to '$' (or other character you prefer to use for indenting, other than <, >, =, space, ...)

This example is for fancy URLs. With the default structure, it would be:
$$<a href="index.php?id=fruits#Grapes Article">Grapes</a>
...


Simple Tree Multi-level Menu (quick hack) - homershines - 2010-04-23

Thanks will try to get onto it tonight.

I really like this component.

Thanks again.

homershines