Fetch the "Alias" field for Joomla menu item - php

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

Related

Missing Menu Item id from wordpress menu

I have just noticed that my menu items id are not getting generated by wordpress.
I expect it to be something like this
<li id='menu-item-2091' class='menu-item menu-item-209'>
<a href='www.mysite.com/members/<?php echo $user_info->user_login; ?>'>Profile</a></li>
but i get this without the menu item id.
<li class='menu-item menu-item-209'>
<a href='www.mysite.com/members/<?php echo $user_info->user_login; ?>'>Profile</a></li>
This error is occurring in my main menu, but my top menu seems to generate the menu item id properly.
I have looked around the menus area and can't find any clues why??
Here is a filter that hacks it out
add_filter ('wp_nav_menu_items','gfb_missing_id_fix', 10, 2);
function gfb_missing_id_fix($menu, $args) {
if($args->theme_location == "primary-menu"){
$dom = new DOMDocument;
$dom->loadHTML($menu);
foreach($dom->getElementsByTagName('li') as $element ) {
$classes = $element->getAttribute("class");
preg_match("/menu-item-\d+/", $classes, $output_array);
$element->setAttribute("id", $output_array[0]);
}
$menu = $dom->saveHTML();
}
return $menu;
}
General info
I use my navigation twice (mobile and desktop with different menu ids) and only the second menu is missing the item ids. This makes sense, because it secures that menu-item-ids are only used once.
JQuery Solution
For me the following javascript / jquery solution does the trick. It adds menu-id-ID (with ID as the actual menu-item-id) to each menu item.
var $mainMenu = $("#main-nav"); // your menu_id used in wp_nav_menu
$mainMenu.find("li").each(function(index, element) {
var $element = $(element);
var classes = $element.attr("class"),
ID = classes.match(/menu-item-(\d+)/)[1];
$element.attr("id", "menu-id-" + ID); // here 'menu-id-' is prepended to the actual ID
});

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

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 associated products

I created a new module to create a section in admin panel. This module section has a sub-section "Associated products" where I can add one or more products to each item in that module.
I am able to get the field values using functions like
$combo->getName()
$combo->getComments()
But I am not able to get the associated products to that item using
$combo->getAssociatedProducts()
What I tried is as follows:
<?php $comboCollection = Mage::getResourceSingleton('combo/combo_collection'); ?>
<?php
foreach ($comboCollection as $combo) {
zend_debug::dump($combo->getAssociatedProducts($combo)); //giving error
}
?>
PS: here $combo is not a product, it is just an item in the created module.
Explanation:
Considering that you have model/collection products for table combo_combo_product. you should get collection for products and then filter it for current combo id of combo collection in this way
foreach ($comboCollection as $combo) {
$associatedCollection = Mage::getResourceSingleton('combo/products_collection');
//$associatedCollection = Mage::getModel('combo/products')->getCollection();
$associatedCollection->addFieldToFilter('combo_id',array('eq' => $combo->getId()));
foreach{$associatedCollection as $item){
print_r($item->getData());
}
}

Get 2 Parent level Joomla Title PHP

I know how to get the Current Page Title, also I know how to get the Menu Active Page Title but I need to actually get the 2 parent Active Menu via PHP.
Active Menu Title
$app = JFactory::getApplication();
$menu = $app->getMenu();
$title = $menu->getActive()->title;
Menu Example
1st Level - CARS
2nd Level - FERRARI
3rd Level - F50
If I am at the 3 level menu F50 how can I get the CARS active menu title?
A method, i used this:
//import to faster development
jimport( 'joomla.application.categories' );
$options = array();
$categories = JCategories::getInstance('Content', $options);
$category = $categories->get($this->category->id);
$parent = $category->getParent();
And here is the magic
//here you get the grandparent category
$grandtemp = $categories->get($parent->id);
$grandparent = $grandtemp->getParent();
//print the values of parent of parent (1st level)
print_r($grandparent)
if you have any question you can comment
Here you go:
$app = JFactory::getApplication();
$menu = $app->getMenu();
$baseId = $menu->getActive($params)->tree[0]; //tree[1] for the second parent etc
//query the database to find the title
$db = JFactory::getDBO();
$query = "SELECT title FROM #__menu WHERE id=".$baseId;
$db->setQuery( $query );
$topParentTitle = $db->loadResult();

Categories