Edit mod_menu to show Images from FLEXIcontent items

More
8 years 3 months ago - 8 years 3 months ago #59276 by iamrobert
Hi,

I have been editing the mod_menu/default_component.php to get images pulled from FLEXIcontent items into my main menu:




Code Demo:
codyhouse.co/demo/mega-site-navigation/index.html

The reason is it seems more intuitive to users than hidden menu or the negatives of getting duplicate URLs without setting the URLs.

It seems to work fine - someone might find it useful or offer suggestions for improvements. You will need to edit it to your fields and your id_type.
Code:
<?php /** * @package Joomla.Site * @subpackage mod_menu * * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; /* My code */ //include constants file require_once (JPATH_ADMINISTRATOR.DS.'components/com_flexicontent/defineconstants.php'); JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_flexicontent'.DS.'tables'); require_once("components/com_flexicontent/classes/flexicontent.fields.php"); require_once("components/com_flexicontent/classes/flexicontent.helper.php"); require_once("components/com_flexicontent/models/".FLEXI_ITEMVIEW.".php"); $itemmodel_name = FLEXI_J16GE ? 'FlexicontentModelItem' : 'FlexicontentModelItems'; if (FLEXI_J16GE) require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'helpers'.DS.'permission.php'); else require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'classes'.DS.'flexicontent.acl.php'); $itemmodel = new $itemmodel_name(); /* End of my code */ // Note. It is important to remove spaces between elements. //$class = $item->anchor_css ? 'class="'.$item->anchor_css.'" ' : ''; $class = $item->anchor_css ? ' '.$item->anchor_css : ''; $title = $item->anchor_title ? 'title="'.$item->anchor_title.'" ' : ''; if ($item->menu_image) { $item->params->get('menu_text', 1) ? $linktype = '<img src="'.$item->menu_image.'" alt="'.$item->title.'" /><span class="image-title">'.$item->title.'</span> ' : $linktype = '<img src="'.$item->menu_image.'" alt="'.$item->title.'" />'; } else { $linktype = $item->title; } switch ($item->browserNav) : default: case 0: /* My Code */ if(isset($item->query['id']) && !empty($item->query['id'])){ $bws_item = $itemmodel->getItem($item->query['id'], $check_view_access=false); FlexicontentFields::getFieldDisplay($bws_item, 'thumb'); // thumb = Name of Image Field $thumb = $bws_item->fields['thumb']->display; if(isset($bws_item->fields['thumb']->thumbs_path)){ // call small image size $bws_src = $bws_item->fields['thumb']->thumbs_path['small'][0]; } if(!empty($bws_src)){ $bws_file = basename($bws_src); $bws_final = "<img alt=\"".$item->title."\" src='".JURI::base().'images/flexicontent/'.$bws_file."' >"; } } /* End of my code */ ?> <?php $bws_block_list = $params->get('block'); $bws_block_array = explode(",",$bws_block_list); ?> <a class="cd-nav-item <?php echo $class; ?>" href="<?php echo $item->flink; ?>" <?php echo $title; ?>><?php if(isset($bws_final) && isset($item->query['id']) && !in_array($item->query['id'],$bws_block_array) && ($bws_item->type_id==10)){ echo $bws_final; }?><span><?php echo $linktype; ?></span></a> <?php break; case 1: // _blank ?><a <?php echo $class; ?>href="<?php echo $item->flink; ?>" target="_blank" <?php echo $title; ?>><?php echo $linktype; ?></a><?php break; case 2: // window.open ?><a <?php echo $class; ?>href="<?php echo $item->flink; ?>" onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes');return false;" <?php echo $title; ?>><?php echo $linktype; ?></a> <?php break; endswitch;
Attachments:
Last edit: 8 years 3 months ago by iamrobert.

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.737 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline