Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do i ad <span></span> to the menu code?
#1
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>
Reply
#2
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.
Reply
#3
Super! and thanks for quick response Wink
Reply
#4
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....
My Github Repos: Github
Website: DigiMute
Reply
#5
Awesome addition, Mike! Update-safe is even better! :-) +1
Reply
#6
absolutely super! thanks
Reply
#7
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);
}
Reply
#8
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(); ?>.
Reply
#9
I can't get the above to work with 3.1.2. Should the above still work with this version please?
Reply




Users browsing this thread: 1 Guest(s)