Posts: 15
Threads: 7
Joined: May 2011
2011-05-29, 05:49:25
(This post was last modified: 2011-05-29, 05:58:14 by motionrepubliq.)
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>
Posts: 524
Threads: 48
Joined: Mar 2011
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.
Posts: 15
Threads: 7
Joined: May 2011
Super! and thanks for quick response
Posts: 1,108
Threads: 70
Joined: Aug 2009
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....
Posts: 524
Threads: 48
Joined: Mar 2011
Awesome addition, Mike! Update-safe is even better! :-) +1
Posts: 15
Threads: 7
Joined: May 2011
Posts: 9
Threads: 4
Joined: Feb 2012
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);
}
Posts: 346
Threads: 27
Joined: Sep 2010
2012-04-05, 16:57:41
(This post was last modified: 2012-04-05, 16:58:39 by logonsf.)
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(); ?>.
Posts: 166
Threads: 7
Joined: Jan 2013
2013-03-02, 07:11:07
(This post was last modified: 2013-03-02, 07:12:02 by davetest.)
I can't get the above to work with 3.1.2. Should the above still work with this version please?