GetSimple Support Forum

Full Version: How do i ad <span></span> to the menu code?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All!

How do i add <span>MY_LINK</span> around my menu links?
I need it to get a specific menu to work :S

I need my links to look like this:
<li><a href="#" title="home" class="current"><span>MY_LINK</span></a></li>
Assuming you're using the out-of-the-box navigation, in file /admin/inc/theme-functions on line 649 you find

Code:
$menu .= '<li class="'. $classes .'"><a href="'. find_url($page['url'],$page['parent']) . '" title="'. strip_quotes($page['title']) .'">'.$page['menu'].'</a></li>'."\n";
You can insert additional markup there. Please note that a later update to GS might overwrite your changes.
Super! and thanks for quick response Wink
or alternatively instead of editing the core files which as Thorsten has explained wil break your site if you update the core files, you could create a functions.php file in your template folder if it does not already exist.

Copy and paste the "get_navigation" function from the /admin/inc/theme_function.php file and rename the function to my_get_navigation or something similar.

CHange the line as outlined above to iclude your <span> tags then in you template call this function instead where your now calling get_navigation.

/mike....
Awesome addition, Mike! Update-safe is even better! :-) +1
absolutely super! thanks
how to add span tag in the theme_function.php

Code:
function get_navigation($currentpage) {

    $menu = '';

    $path = GSDATAPAGESPATH;
    $dir_handle = opendir($path) or die("Unable to open $path");
    $filenames = array();
    while ($filename = readdir($dir_handle)) {
        $filenames[] = $filename;
    }
    
    $count="0";
    $pagesArray = array();
    if (count($filenames) != 0) {
        foreach ($filenames as $file) {
            if ($file == "." || $file == ".." || is_dir($path . $file) || $file == ".htaccess"  ) {
                // not a page data file
            } else {
                $data = getXML($path . $file);
                if ($data->private != 'Y') {
                    $pagesArray[$count]['menuStatus'] = $data->menuStatus;
                    $pagesArray[$count]['menuOrder'] = $data->menuOrder;
                    $pagesArray[$count]['menu'] = strip_decode($data->menu);
                    $pagesArray[$count]['url'] = $data->url;
                    $pagesArray[$count]['title'] = strip_decode($data->title);
                    $pagesArray[$count]['parent'] = $data->parent;
                    $count++;
                }
            }
        }
    }
    
    $pagesSorted = subval_sort($pagesArray,'menuOrder');
    if (count($pagesSorted) != 0) {
        foreach ($pagesSorted as $page) {
            $sel = ''; $classes = '';
            $url_nav = $page['url'];
            
            if ($page['menuStatus'] == 'Y') {
                if ("$currentpage" == "$url_nav") { $classes = "current ". $page['parent'] ." ". $url_nav; } else { $classes = trim($page['parent'] ." ". $url_nav); }
                if ($page['menu'] == '') { $page['menu'] = $page['title']; }
                if ($page['title'] == '') { $page['title'] = $page['menu']; }
                $menu .= '<li class="'. $classes .'"><a href="'. find_url($page['url'],$page['parent']) . '" title="'. strip_quotes($page['title']) .'">'.$page['menu'].'</a></li>'."\n";
            }
        }
        
    }
    
    closedir($dir_handle);
    echo exec_filter('menuitems',$menu);
}
ANSH7662 Wrote:how to add span tag in the theme_function.php

Code:
function get_navigation($currentpage) {

    $menu = '';

    $path = GSDATAPAGESPATH;
    $dir_handle = opendir($path) or die("Unable to open $path");
    $filenames = array();
    while ($filename = readdir($dir_handle)) {
        $filenames[] = $filename;
    }
    
    $count="0";
    $pagesArray = array();
    if (count($filenames) != 0) {
        foreach ($filenames as $file) {
            if ($file == "." || $file == ".." || is_dir($path . $file) || $file == ".htaccess"  ) {
                // not a page data file
            } else {
                $data = getXML($path . $file);
                if ($data->private != 'Y') {
                    $pagesArray[$count]['menuStatus'] = $data->menuStatus;
                    $pagesArray[$count]['menuOrder'] = $data->menuOrder;
                    $pagesArray[$count]['menu'] = strip_decode($data->menu);
                    $pagesArray[$count]['url'] = $data->url;
                    $pagesArray[$count]['title'] = strip_decode($data->title);
                    $pagesArray[$count]['parent'] = $data->parent;
                    $count++;
                }
            }
        }
    }
    
    $pagesSorted = subval_sort($pagesArray,'menuOrder');
    if (count($pagesSorted) != 0) {
        foreach ($pagesSorted as $page) {
            $sel = ''; $classes = '';
            $url_nav = $page['url'];
            
            if ($page['menuStatus'] == 'Y') {
                if ("$currentpage" == "$url_nav") { $classes = "current ". $page['parent'] ." ". $url_nav; } else { $classes = trim($page['parent'] ." ". $url_nav); }
                if ($page['menu'] == '') { $page['menu'] = $page['title']; }
                if ($page['title'] == '') { $page['title'] = $page['menu']; }
                $menu .= '<li class="'. $classes .'"><a href="'. find_url($page['url'],$page['parent']) . '" title="'. strip_quotes($page['title']) .'">'.$page['menu'].'</a></li>'."\n";
            }
        }
        
    }
    
    closedir($dir_handle);
    echo exec_filter('menuitems',$menu);
}

Change get_navigation to get_navigation_span in the top line, then change:

Code:
$menu .= '<li class="'. $classes .'"><a href="'. find_url($page['url'],$page['parent']) . '" title="'. strip_quotes($page['title']) .'">'.$page['menu'].'</a></li>'."\n";

to

Code:
$menu .= '<li class="'. $classes .'"><span class="'. $classes .'"><a href="'. find_url($page['url'],$page['parent']) . '" title="'. strip_quotes($page['title']) .'">'.$page['menu'].'</a></span></li>'."\n";

Then when you call for the navigation in your theme, use <?php get_navigation_span(); ?>.
I can't get the above to work with 3.1.2. Should the above still work with this version please?