2017-02-12, 03:59:59
(2017-02-06, 04:45:37)Tyblitz Wrote:(2017-02-05, 20:12:26)BF68 Wrote: Ah figured it already out, I18N_SHOW_NORMAL does the job, now on to the next challenge:
How can I have a menu as in the above sample where a click to "Hobbies" does NOT open a page but only opens the submenu? Is this possible?
Hi there, BF68,
There is no such feature included out of the box that I know of.
A while ago I wrote a function for I18N navigation where:You can see it at this website: http://seiltanzen.com
- if the page has child pages, it only opens the sub-menu.
- if the page doesn't have child pages, it opens the page.
The code is the following (include it in your theme):
PHP Code:function i18nMenuNoLandingPages($links, $loop = 0) {
global $SITEURL, $language;
$y = count($links);
static $str = '';
$str = $str . '<ul>';
for ($x = 0; $x < $y ; $x++) {
$item = $links[$x];
$str = $str . '<li>';
if ($item['haschildren']) {
$str = $str . $item['title'];
$str = i18nMenuNoLandingPages($item['children'], $loop++, $str);
} else if ($item['haschildren'] === false) {
// depending on your URL structure, you will need to change this line
$str = $str . '<a href="' . $SITEURL . (strlen($item['parent']) ? $item['parent'] .'/' : ''). $item['url'] . '">' . $item['title'] . '</a>';
}
$str = $str . '</li>';
}
$str = $str . '</ul>';
return $str;
}
And you use it like this:
PHP Code:$nav = return_i18n_menu_data(return_page_slug(),0,5,I18N_SHOW_MENU);
echo i18nMenuNoLandingPages($nav);
However: depending on your .htaccess rewrite rules and whether you use pretty urls, you will need to change one line in the code. In your admin dashboard, have you checked "Use fancy URLs?" and set a custom permalink structure?
This code was written for a permalink structure like: /%parent%/%slug%/ (eg. http://mysite/hobbies/fishing).
Hy Tyblitz,
Unfortunately your function does not really what I expect as it opens all submenues instantly and not only when someone clicks on the menu entry. Do you have any hint about how to modify your code to get the thing done?