Drupal template, verify that the page is a menu item - php

Helló!
I want to examine that the actual page is in the menu.
I want to do with drupal template (page.tpl.php).
For example:
if ($page_is_a_menuitem):
echo "This page is in the menu";
else:
echo "This page not in the menu";
endif;
Because if the page is in the menu a want to highlight the title.
Sorry for my bad english.

Try this
this is return to a all menu list :- menu_get_menus(true)
like this
Array
(
[menu-footer-menu] => Footer Menu
[main-menu] => Main menu
[management] => Management
[navigation] => Navigation
[user-menu] => User menu
)
and you want to get main menu inside a all list to use this
$tree = menu_tree_all_data('main-menu')
this is return in main-menu in all items
otherwise you use a this code
$path = current_path();
$selected_menu= '';
$menu = menu_link_get_preferred($path = NULL, $selected_menu = NULL);
$menu is return a current page manu detail after you want
echo "this menu is ".$menu['menu_name'] .' and menu title is '.$menu['title'];

get the whole menu tree
$tree = menu_tree_page_data('primary-links');
and check in page tpl if the node id exists in the menu...

Related

How to display sub categories using Collapsing Categories plugin

My site is using the Collapsing Categories plugin (Robert Felty). As a sidebar widget, it is working the way we want it. But now I've written a page, and I'm inserting the php code in the page, and I don't know how to make it display the same Blog sub categories that it displays on any blog post page.
The sub-categories of the blog category are:
- from-the-experts
- grilling-lifestyle
- grilling-tips-and-techniques
But when I add the php code to the page (using the page editor), it outputs all the top level categories, instead:
►Blog (118)
►Lamb (1)
►News (1)
►Recipes (59)
►Uncategorized (4)
This is the php code, taken from the readme.txt page:
[php]
echo "<ul class='collapsCatList'>\n";
if (function_exists('collapsCat')) {
collapsCat();
} else {
wp_get_categories('your_options_here');
}
echo "</ul>\n";
[/php]
What I want to know is what I have to put in that code to display only the few sub categories I want displayed.
Answered by plugin author here
$my_options=array(
'inExclude' => 'include',
'inExcludeCats' => 'blog',
'showTopLevel' => false
);
echo "<ul class='collapsCatList'>\n";
if (function_exists('collapsCat')) {
collapsCat($my_options);
} else {
wp_get_categories('your_options_here');
}
echo "</ul>\n";

Wordpress Sub Menu / Show Sister Pages

I am currently using this snippet to show children of the current page.
<?php wp_list_pages('title_li=&child_of='.$post->ID.''); ?>
when I click one of those children pages the sub nav disappears because there are no child pages of the current page, so what I need it to do is continue to show the sister pages of the current page.
What is the best way to do this?
You could request the parent ID instead of the post ID if there is no childs on the current page :
$page_query = new WP_Query();
$all_pages = $page_query->query(array('post_type' => 'page'));
$childs = get_page_children($post-ID, $all_pages);
if(!empty($childs)) {
// display the page childs
wp_list_pages($post->ID);
} else {
// display the page siblings
wp_list_pages(wp_get_post_parent_id($post->ID));
}
get_page_children is used to check if there is any child for the current page - the WP_Query part is needed for get_page_children which required an array of all the pages to look in.

Get name of top-level menu - Joomla 3

I have some menu-items published on footer of my site.
-FAQ
-Contact Us
These are actually menu-items and their main menu name is Information
I want to show their main-menu name as well like so:
Information
-FAQ
-Contact Us
I have this code
$menu = JFactory::getApplication()->getMenu();
$parent_title = $menu->getItem(2)->title;
The main menu named Information has id 2 but it does not show anything :(
So how do I get that menu name?
Lets try this way:
$menu = JFactory::getApplication()->getMenu();
$active = $menu->getActive();
$parent = $menu->getItem($active->parent_id);
var_dump(parent);
and tell us what you get : )
if this don't work for you, change line with parent to:
$parent = $menu->getItems('id', $active->parent_id);
regards

Adding dynamic Link to menu Item in wordpress

I want to have 'Text only' in menu of my wordpress website without plugin.So how to set dynamic link to menu item in wordpress?
try this one
add_filter('wp_nav_menu_items', 'menu_link', 10, 2);
function menu_link($items, $args) {
if ($args->menu == 'footer'){
$items .= '<li class="copyright ">Text Only</li>';
$items .= '<li class="copyright ">Print Page</li>';
}
return $items;
// return $items1;
}
You will have to recreate the complete menu walker to make it text only, or remove the anchor through jquery. But if you just want a menu item that doesn't link anywhere, create a normal link menu item, and instead of an actual link use #.

HighLighted item menu when clicked in codeIgniter

how can i make the active menu in codeIgniter, its not when hover, but when clicked, for example if we are in some category, that item in the menu is highlighted, how can be this done in CI?
Depends on your routing and menu generation script. Esiest method is to check for segments in uri. For example for static menu You can do this:
<?php $class = $this->uri->segment(1)=="someController"?"highlighted":""; ?>
Menu item
There are a few steps involved here.
Firstly, you need to determine which is the 'current' menu item or category. If you can structure your site so that there's a direct relationship between your URL structure and your top level menu items (and / or your categories) then this will help a lot.
You'll need a common section of code that generates your main menu. This code could iterate through an array of menu item titles to produce the HTML for the menu. If the array had keys for the URL segment and values for the menu item text...
$menuItems = Array(
"/home" => "Home",
"/products" => "Products",
"/faq" => "FAQ",
"/aboutus" => "About Us"
);
(Leading slashes included for clarity as to which are the URI segments and which are the Menu Titles only - you would usually omit the leading slash)
... then, while you're iterating through, you could check each item against the relevant segment of the current URL.
Secondly, having worked out which is the current item, you could add a css class to the relevant HTML element.
e.g.
$menuHtml = "<ul class='menu'>\r\n";
foreach($menuItems as $segment => $title) {
if($segment == $this->uri->segment(1)) {
$menuHTML .= "<li class='current'>$title</li>";
} else {
$menuHTML .= "<li>$title</li>\r\n";
}
}
$menuHtml .= "</ul>";
You'd then need to apply the required highlight styles in CSS to the li.current element:
li.current {
<your-highlight-css-styles-here>
}

Categories