GetSimple Support Forum
How do i ad <span></span> to the menu code? - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: General Questions and Problems (http://get-simple.info/forums/forumdisplay.php?fid=16)
+--- Thread: How do i ad <span></span> to the menu code? (/showthread.php?tid=1775)



How do i ad <span></span> to the menu code? - rune1980 - 2011-05-29

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>


How do i ad <span></span> to the menu code? - polyfragmented - 2011-05-29

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.


How do i ad <span></span> to the menu code? - rune1980 - 2011-05-29

Super! and thanks for quick response Wink


How do i ad <span></span> to the menu code? - n00dles101 - 2011-05-29

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....


How do i ad <span></span> to the menu code? - polyfragmented - 2011-05-29

Awesome addition, Mike! Update-safe is even better! :-) +1


How do i ad <span></span> to the menu code? - rune1980 - 2011-05-29

absolutely super! thanks


How do i ad <span></span> to the menu code? - ANSH7662 - 2012-04-04

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);
}



How do i ad <span></span> to the menu code? - Angryboy - 2012-04-05

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(); ?>.


RE: How do i ad <span></span> to the menu code? - davetest - 2013-03-02

I can't get the above to work with 3.1.2. Should the above still work with this version please?