Get name of top-level menu - Joomla 3 - php

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

Related

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.

Drupal template, verify that the page is a menu item

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

get parent category of current category

I'm working on a website where my clients want me to display the parent category of current category. I know how to display the category of current product.
Mage::registry('current_category')->getName();
But I'm struggling to get the parent category of that category. Please help me regarding this. I'm a budding developer.
To get Parent Category Id you must know the current category Id, for that you need to write
<?php
$_cat = new Mage_Catalog_Block_Navigation();
$curent_cat = $_cat->getCurrentCategory();
$curent_cat_id = $curent_cat->getId();?>
Now you can get Parent Category Id.
write the code given below to get the Id
<?php $parentId=Mage::getModel('catalog/category')->load($curent_cat_id)->getParentId();
echo $parentId; // $parentId will print your current category's parent Id
?>
Please refer this blog it contains the necessary information to achieve your requirement
Best of Luck :)
You can simply use this short code to get the parent category:
$parentId = Mage::registry('current_category')->getParentId();
$parent = Mage::getModel('catalog/category')->load($parentId);
exit($parent->getName());

How to get original (All store views) current category name in Magento?

How can I get "original" category name in Magento where I already translated category name for current store view. I would like to get category name as entered in All Store views because I would like to send original (English) name to GA for tracking - I need this when I'm on category page.
I can get localized category name in this way:
<?php
$currentCategory = Mage::registry('current_category');
$name = $currentCategory->getName();
?>
But couldn't find a way to get untranslated name without additional calls to database.
As mentioned above, this will need additional database requests. The following should work:
$defaultStoreCategory = Mage::getModel('catalog/category');
$defaultStoreCategory->setStoreId(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID);
$defaultStoreCategory->load($currentCategory->getId());
$name = $defaultStoreCategory->getName();
Try with this code
$storeId = Mage::app()->getStore()->getId();
$product = Mage::getModel('catalog/category')
->setStoreId(Mage::app()->getStore()->getId())
->load(YOUR_CATEGORY_ID);
Hope this helps.

Fetch the "Alias" field for Joomla menu item

Is there a way to get the Alias field of a main menu item in Joomla 1.5 from mod_mainmenu module? I know you can access the menu using this code:
$menu = JSite::getMenu();
I need to use the Alias field to hold a sub-title for the menu item. Is it possible to fetch this from the modMainMenuXMLCallback() function in mod_mainmenu? Thanks.
$menu = JSite::getMenu();
$alias = $menu->getItem($id)->alias; // if you have id of menu
$menu = JSite::getMenu();
$alias = $menu->getActive()->alias; // alias of active menu

Categories