More efficient way to build dynamic menu - php

I am creating a dynamic menu whos items appear depending on a set 'mode' (that is passed via ajax). Off this it creates the menu, disabling and hiding icons that are not associated with that mode.
The problem is, in my implementation there are a lot of if conditions. Can anyone show me a cleaner way of doing what I am trying to achieve?
My code is:
public function gridMenu()
{
$mode = Validate::sanitize($_POST['mode']);
$modes = array(
'products' => array('edit', 'delete', 'archive')
);
$output = '<div id="hexContainer">';
for($i = 1; $i < 7; $i++) {
$img = '';
$output .= '<div class="hex hex' . $i;
if($i == 1)
{
if(in_array('edit', $modes[$mode]))
{
$output .= ' hex-selectable';
$img = '<img data-option="Edit" src="' . ROOT . 'images/edit.png">';
} else {
$output .= ' hex-disabled';
}
}
if($i == 2)
{
if(in_array('zzz', $modes[$mode]))
{
$output .= ' hex-selectable';
} else {
$output .= ' hex-disabled';
}
}
if($i == 3)
{
if(in_array('delete', $modes[$mode]))
{
$output .= ' hex-selectable';
$img = '<img data-option="Delete" src="' . ROOT . 'images/delete.png">';
} else {
$output .= ' hex-disabled';
}
}
if($i == 4)
{
if(in_array('xxx', $modes[$mode]))
{
$output .= ' hex-selectable';
} else {
$output .= ' hex-disabled';
}
}
if($i == 5)
{
if(in_array('archive', $modes[$mode]))
{
$output .= ' hex-selectable';
$img = '<img data-option="Archive" src="' . ROOT . 'images/archive.png">';
} else {
$output .= ' hex-disabled';
}
}
if($i == 6)
{
if(in_array('zzz', $modes[$mode]))
{
$output .= ' hex-selectable';
} else {
$output .= ' hex-disabled';
}
}
$output .= '">';
$output .= $img;
$output .= '</div>';
}
$output .= '<div class="hex hex-mid"></div>';
$output .= '</div>';
echo $output;
}

Use the switch function:
switch ($i){
case 1:
//code for $i==1
break;
case 2:
// code for $i==2
break;
//...
}

This hasn't been tested, but you could try something along the lines of this.
Basically from your code I'm assuming that you're trying to insert an image only on the odd rounds. So with that I created a $_modes and $_mode variables which will hold the values for each round.
With these values, we will automatically create the HTML classes using the rules you have set in your code, and on each round if it's odd, and in the array then we also add the image.
public function gridMenu() {
$mode = Validate::sanitize($_POST['mode']);
$modes = array(
'products' => array('edit', 'delete', 'archive')
);
$_modes = array(
false,
array('Edit', 'edit'),
array('ZZZ', 'zzz'),
array('Delete', 'delete'),
array('XXX', 'xxx'),
array('Archive', 'archive'),
array('ZZZ', 'zzz'),
);
$output = '<div id="hexContainer">';
for($i = 1; $i < 7; $i++) {
$_mode = $_modes[$i];
$img = '';
$classnames = array('hex', 'hex' . $i);
if ( ($i % 2) === 0 && in_array($_mode[1], $modes[$mode])) {
$img = '<img data-option="' . $_mode[0] . '" src="' . ROOT . 'images/' . $_mode[1] . '.png">';
}
$classnames[] = (in_array($_mode[1], $modes[$mode]) ? 'hex-selectable' : 'hex-disabled');
$output .= '<div class="' . implode(' ', $classnames) . '">';
$output .= $img;
$output .= '</div>';
}
$output .= '<div class="hex hex-mid"></div>';
$output .= '</div>';
echo $output;
}

Related

How to add static li inside dynamic list using php?

I have 5 menu in the website which is coming dynamically :
menu1 menu2 menu3 menu4 menu5
Now I want to add menu6 before menu5 using php.
My code:
foreach ($collection as $category) {
$i++;
$menuCategory = $this->getCategoryAsArray($category, $currentCategory);
$class = '';
$class .= 'nav'. $i;
if($i == 1) {
$class .= ' first';
} elseif ($i == $count) {
$class .= ' last';
}
if($menuCategory['is_active']) {
$class .= ' active';
}
//if($this->hasChildProduct($category)) {
//$class .= ' parent';
//}
if($this->hasChildSubCategory($category)) {
$class .= ' parent';
}
$class .= ' level-top';
$html .= '<li class="level0 '. $class .'">';
$html .= '<a href="'. $menuCategory['url'] .'">';
$html .= '<span>'. $menuCategory['name'] .'</span>';
$html .= '</a>';
//if($this->hasChildProduct($category)) {
//$html .= $this->getChildProductMenuHtml($category, $i);
//}
if($this->hasChildSubCategory($category)) {
$html .= $this->getChildSubcategoryMenuHtml($category, $i);
}
$html .= '</li>';
}
Menu6 is the static link which code is:
<li class="vertical-submenu" id="static-menu"><a href="<?php echo $block->getUrl('menu6')?>"><?php echo __('menu6')?></li>
I am not getting the code because i am not aware of values coming in the array in foreach loop.
But I can explain the situation to you via Algorithm.
$i = 0;
foreach(expression){
if(value == "menu5"){
write("Menu 4")
}
Write("Menu ".$i)
$i++;
}
Hope your problem is resolved with this. If you need anything else or want to elaborate more about you problem text me at shahrukhusmaani#gmail.com

SP Page Builder php errors ( Undefined variable, Undefined property)

i installed a Joomla template and some errors are appearing in homepage, the Errors are related to the Sp Page Builder component.
How can i fix these errors?
Here's a document with the erros - https://drive.google.com/open?id=0B1toGflgmV7fZi1SQ051QWZxZFE
And the site.php
<?php
/**
* Flex 1.0 #package SP Page Builder
* Template Name - Flex
* #author Aplikko http://www.aplikko.com
* #copyright Copyright (c) 2015 Aplikko
* #license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
// no direct access
defined('_JEXEC') or die;
JLoader::register('JHtmlString', JPATH_LIBRARIES.'/joomla/html/html/string.php');
AddonParser::addAddon('sp_latest_posts','sp_latest_posts_addon');
function get_categories($parent=1) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select('*')
->from($db->quoteName('#__categories'))
->where($db->quoteName('extension') . ' = ' . $db->quote('com_content'))
->where($db->quoteName('published') . ' = ' . $db->quote(1))
->where($db->quoteName('parent_id') . ' = ' . $db->quote($parent))
->order($db->quoteName('created_time') . ' DESC');
$db->setQuery($query);
$cats = $db->loadObjectList();
$categories = array($parent);
foreach ($cats as $key => $cat) {
$categories[] = $cat->id;
}
return $categories;
}
function sp_latest_posts_addon($atts){
extract(spAddonAtts(array(
"title" => '',
"heading_selector" => 'h3',
"title_fontsize" => '',
"title_text_color" => '',
"title_margin_top" => '',
"title_margin_bottom" => '',
"show_image" => '',
"show_date" => '',
"show_category" => '',
"show_intro_text" => '',
"show_author" => '',
"item_limit" => '',
"intro_text_limit" => '100',
"column_no" => '3',
"image_alignment" => '',
"category" => '',
"style" => '',
"class" => '',
), $atts));
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
// Database Query
require_once JPATH_SITE . '/components/com_content/helpers/route.php';
// Access filter
$access = !JComponentHelper::getParams('com_content')->get('show_noauth');
$authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select('a.*')
->from($db->quoteName('#__content', 'a'))
->select($db->quoteName('b.alias', 'category_alias'))
->select($db->quoteName('b.title', 'category'))
->join('LEFT', $db->quoteName('#__categories', 'b') . ' ON (' . $db->quoteName('a.catid') . ' = ' . $db->quoteName('b.id') . ')')
->where($db->quoteName('b.extension') . ' = ' . $db->quote('com_content'))
->where($db->quoteName('a.state') . ' = ' . $db->quote(1))
->where($db->quoteName('a.catid')." IN (" . implode( ',', get_categories($category) ) . ")")
->where($db->quoteName('a.access')." IN (" . implode( ',', $authorised ) . ")")
->order($db->quoteName('a.created') . ' DESC')
->setLimit($item_limit);
$db->setQuery($query);
$items = $db->loadObjectList();
// End Database Query
$style == 'flex' ? $flex_style = ' flex' : '';
$style == 'blog' ? $blog_style = ' blog' : '';
$blog_style = $output = '<div class="sppb-addon sppb-addon-latest-posts'.$flex_style.$blog_style.' sppb-row ' . $class . '">';
if ($title) {
$output .= '<div class="sppb-section-title">';
$output .= '<'.$heading_selector.' class="sppb-addon-title" style="' . $title_style . '"> ' . $title . '</' . $heading_selector . '>';
$output .= '</div>'; // END :: title
}
$output .= '<div class="sppb-addon-content">';
$output .= '<div class="latest-posts clearfix">';
foreach(array_chunk($items, $column_no) as $items) {
$output .= '<div>';
foreach ($items as $item) {
$item->slug = $item->id . ':' . $item->alias;
$item->catslug = $item->catid . ':' . $item->category_alias;
$item->user = JFactory::getUser($item->created_by)->name;
if ($access || in_array($item->access, $authorised)) {
// We know that user has the privilege to view the article
$item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid, $item->language));
$item->catlink = JRoute::_(ContentHelperRoute::getCategoryRoute($item->catslug, $item->catid, $item->language));
} else {
$item->link = JRoute::_('index.php?option=com_users&view=login');
$item->catlink = JRoute::_('index.php?option=com_users&view=login');
}
$tplParams = JFactory::getApplication()->getTemplate(true)->params;
$params = $item->params;
$attribs = json_decode($item->attribs);
$images = json_decode($item->images);
$imgsize = $tplParams->get('blog_list_image', 'default');
$intro_image = '';
if(isset($attribs->spfeatured_image) && $attribs->spfeatured_image != '') {
if($imgsize == 'default') {
$intro_image = $attribs->spfeatured_image;
} else {
$intro_image = $attribs->spfeatured_image;
$basename = basename($intro_image);
$list_image = JPATH_ROOT . '/' . dirname($intro_image) . '/' . JFile::stripExt($basename) . '_'. $imgsize .'.' . JFile::getExt($basename);
if(file_exists($list_image)) {
$intro_image = JURI::root(true) . '/' . dirname($intro_image) . '/' . JFile::stripExt($basename) . '_'. $imgsize .'.' . JFile::getExt($basename);
}
}
} elseif(isset($images->image_intro) && !empty($images->image_intro)) {
$intro_image = $images->image_intro;
}
if($column_no == '1') {
if ($show_image) {
$image_alignment == 'left' ? $img_column = 'sppb-col-sm-4 column-1 pull-left match-height' : $img_column = 'sppb-col-sm-4 column-1 pull-right match-height';
}
if ($show_image) {
$image_alignment == 'right' ? $content_column = 'sppb-col-sm-8 column-1 pull-left match-height' : $content_column = 'sppb-col-sm-8 column-1 pull-right match-height';
} else {
$image_alignment == 'right' ? $content_column = 'sppb-col-sm-12 column-1' : $content_column = 'sppb-col-sm-12 column-1';
}
$h2style = ' style="font-size:180%;line-height:1.4;"';
$img_wrapper_margin = ' style="margin:0;"';
if ($image_alignment == 'left') {
$inner_padding = ' style="padding:0 0 0 30px;"';
} else {
$inner_padding = ' style="padding:0 30px 0 0;"';
}
}
// match-height
$column_no > '1' ? $match_height = ' match-height' : '';
// Flex Style
if($style == 'flex') {
$output .= '<div class="latest-post sppb-col-sm-' . round(12/$column_no) . ' columns-'.$column_no.'">';
$output .= '<div class="latest-post-item">';
if($column_no == '1') {
$output .= '<div class="row-fluid">';
}
if(!empty($intro_image) || (isset($images->image_intro) && !empty($images->image_intro))) {
if ($show_image) {
if($column_no == '1') {
$output .= '<div style="padding:0" class="'.$img_column.'">';
}
$output .= '<div class="img-wrapper">';
$output .= '<img class="post-img" src="' . $intro_image . '" alt="' . $item->title . '" /><div class="caption-content">' . $item->title . '<em class="caption-category"><span class="posted-in">'. JText::_('COM_SPPAGEBUILDER_ADDON_POSTED_IN') .'</span>'. $item->category . '</em></div>';
$output .= '</div>';
if($column_no == '1') {
$output .= '</div>';
}
}
}
if($column_no == '1') {
$output .= '<div'.$inner_padding.' class="'.$content_column.'">';
}
$output .= '<div class="latest-post-inner match-height">';
if (($show_date || $show_intro_text || $show_author) != 1) {
$output .= '<h2 style="margin:0" class="entry-title">' . $item->title . '</h2>';
} else {
$output .= '<h2'.$h2style.' class="entry-title">' . $item->title . '</h2>';
}
if ($show_date) {
$output .= '<div class="entry-meta"><span class="entry-date">' . JHtml::_('date', $item->created, 'DATE_FORMAT_LC1') . '</span></div>';
}
if ($show_intro_text) {
$output .= '<p class="intro-text" >' . JHtml::_('string.truncate', strip_tags($item->introtext), $intro_text_limit) . '</p>';
}
$show_author || $show_category ? $output .= '<hr />' : '';
if ($show_author) {
$output .= '<span class="post-author"><span class="entry-author">' . JText::_('COM_SPPAGEBUILDER_ADDON_POSTED_BY'). '</span> ' . $item->user . '</span>';
}
if ($show_category) {
$show_author ? $posted_in_category = ' cat-inline' : '';
$output .= '<span class="category'.$posted_in_category.'"><span class="posted-in">'. JText::_('COM_SPPAGEBUILDER_ADDON_CATEGORY') .'</span>'. $item->category . '</span>';
}
if($column_no == '1') {
$output .= '</div>';
$output .= '</div>';
}
$output .= '</div>';
if($column_no == '1') {
$output .= '<div class="post-divider"></div>';
}
$output .= '</div>';
// Default & Blog styles
} else {
$output .= '<div class="latest-post sppb-col-sm-' . round(12/$column_no) . ' columns-'.$column_no.'">';
$output .= '<div class="latest-post-inner' . $match_height . '">';
if($column_no == '1') {
$output .= '<div class="row-fluid">';
}
if ($show_image) {
if($column_no == '1') {
$output .= '<div class="'.$img_column.'">';
}
$output .= '<div'.$img_wrapper_margin.' class="img-wrapper">';
$output .= '<img class="post-img" src="' . $intro_image . '" alt="' . $item->title . '" />';
$output .= '</div>';
if($column_no == '1') {
$output .= '</div>';
}
}
if($column_no == '1') {
$output .= '<div class="'.$content_column.'">';
}
if ($show_date) {
$output .= '<div class="entry-meta"><span class="entry-date"> ' . JHtml::_('date', $item->created, 'DATE_FORMAT_LC1') . '</span></div>';
}
$output .= '<h2'.$h2style.' class="entry-title">' . $item->title . '</h2>';
if ($show_intro_text) {
$output .= '<p class="intro-text" >' . JHtml::_('string.truncate', strip_tags($item->introtext), $intro_text_limit) . '</p>';
}
$show_author || $show_category ? $output .= '<hr />' : '';
if ($show_author) {
$output .= '<span class="post-author"><span class="entry-author">' . JText::_('COM_SPPAGEBUILDER_ADDON_POSTED_BY'). ' ' . $item->user . '</span></span>';
}
if ($show_category) {
$show_author ? $posted_in_category = ' cat-inline' : '';
$output .= '<span class="category'.$posted_in_category.'"><span class="posted-in">'. JText::_('COM_SPPAGEBUILDER_ADDON_CATEGORY') .'</span>'. $item->category . '</span>';
}
if($column_no == '1') {
$output .= '</div>';
$output .= '</div>';
}
$output .= '</div>';
}
$output .= '</div>';
}
$output .= '</div>';
}
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
$column_no == '1' ? $column_no_1 = '.column-1 {margin:10px auto;padding:0!important;}' : '';
// Add styles #media rulepost-img
if($style == 'flex') {
$custom_style = ''
. '#media screen and (max-width: 768px) {'
. $column_no_1
. '.img-wrapper a {font-size:150%;line-height:1.5;}'
. '}';
$doc->addStyleDeclaration($custom_style);
}
if ($column_no>='3') {
$custom_style_3 = ''
. '#media screen and (min-width: 992px) and (max-width: 1199px){'
. '.columns-'.$column_no.'{width:33.3333%;}'
. '}'
. '#media screen and (min-width: 768px) and (max-width: 991px){'
. '.columns-'.$column_no.'{width:50%}'
. '}';
$doc->addStyleDeclaration($custom_style_3);
}
if($column_no=='5') {
$custom_style_5 = ''
. '.columns-'.$column_no.' {width:20%}'
. '#media screen and (min-width: 992px) and (max-width: 1199px){'
. '.columns-'.$column_no.'{width:33.3333%;}'
. '}'
. '#media screen and (min-width: 768px) and (max-width: 991px){'
. '.columns-'.$column_no.'{width:50%}'
. '}'
. '#media screen and (max-width: 767px){'
. '.columns-'.$column_no.'{width:100%}'
. '}';
$doc->addStyleDeclaration($custom_style_5);
}
return $output;
}
Thanks!
There is many errors, but all of them are variable that have not been declared before using it, as example :
$style == 'flex' ? $flex_style = ' flex' : '';
$style == 'blog' ? $blog_style = ' blog' : '';
$blog_style = $output = '<div class="sppb-addon sppb-addon-latest-posts'.$flex_style.$blog_style.' sppb-row ' . $class . '">';
In this case $flex_style and $blog_style are not declared, you should write this instead :
$flex_style = style == 'flex' ? ' flex' : '';
$blog_style = $style == 'blog' ? ' blog' : '';
That is just an example, but if you search a little you'll find other issue like this one.

Adding background color to element within php if-statement

I have the following code in which I want to add an element to my if statement, but I am unsure how to approach this. What I am looking to do is add a background-color to the else part of it. Within this:
else {
$status_img = '<img src="../icons/collection/checkmark.png" alt="Goal Complete">';
}
So if $status is not 0, I want to set background color for the class goal-box-right.
Is there anyway I can manipulate the CSS through php like this?
foreach ($rows as $row) {
$status = $row['status'];
if ($status == 0) {
$status_img = '<img src="../icons/collection/x-sign.png" alt="Goal Not Complete">';
}
else {
$status_img = '<img src="../icons/collection/checkmark.png" alt="Goal Complete">';
}
$goal_date = $row['date'];
$fixed_goal_date = fixDate($goal_date);
$html = "";
$html .= '<div class="goal-box" id="comment-'.$row['id'].'">';
$html .= '<div class="goal-box-left">'; //added
$html .= '<div class="goal-post-status">'.$status_img. '</div>';
$html .= '</div>'; //added
$html .= '<div class="goal-box-right">'; //added
$html .= '<div class="goal-post-title">'.$row['title']. '</div>';
$html .= '<div class="goal-post-date">'.$fixed_goal_date. '</div>';
$html .= '<div class="goal-post-description">'.$row['description']. '</div>';
$html .= '</div>'; //added
$html .= '</div>';
Separate the logic - add a CSS class based on the status then set the colours in the stylesheet.
$class = $status != 0 ? 'status-nonzero' : '';
$html .= '<div class="goal-box-right ' . $class . '">';
CSS:
.goal-box-right.status-nonzero { background-color: #foo }
Advantage is keeping the style logic in the CSS where it belongs and away from the code that's generating the HTML.
So what's the problem:
$style = '';
if ($status == 0) {
$style = ' style="your-style:here"';
$status_img = '<img src="../icons/collection/x-sign.png" alt="Goal Not Complete">';
}
else {
$status_img = '<img src="../icons/collection/checkmark.png" alt="Goal Complete">';
}
// ...
$html .= '<div class="goal-box-right"' . $style . '>'; //added

How can I echo two items per one time by using PHP Foreach?

I'm using PHP to echo my products from the database. If we just use foreach, we will get the result one item per a loop, but actually I want it echo two items per one times as ub the below function.
This is my PHP function using foreach to fetch data from database.
I've used row item selector to wrap product selector, so I want to echo a block of product two times, and then it should echo the row item.
Example: row item = 1 then product = 2
public function last_upated_products() {
$data = $this->newest_products_from_db('products');
$out = '';
if ($data) {
foreach ($data as $k => $row) {
$out .= '<div class="row item">';
$out .= '<div class="product">';
$out .= '<div class="image">';
$out .= '<img src="' . base_url('asset/img/main/9.jpg') . '" alt="img" class="img-responsive">';
$out .= '<div class="promotion"><span class="discount">' . $row['prod_id'] . '% OFF</span> </div>';
$out .= '</div>';
$out .= '<div class="description"><div class="price"><span>$' . $row['prod_price'] . '</span></div><h4>' . $row['prod_name'] . '</h4>';
$out .= '<p>' . $row['prod_descrip'] . '</p>';
$out .= '</div>';
$out .= '</div>';
$out .= '</div>';
}
}
return $out;
}
This function will echo one item for a loop.
You can not print two times in one iteration of a loop. You can use conditional HTML output to do this job.
Consider this:
function last_upated_products() {
$data = $this->newest_products_from_db('products');
$out = '';
$counter = 1;
$length = count($data);
if ($data) {
foreach ($data as $k => $row) {
if ($counter % 2 != 0) {
$out .= '<div class="row item">';
}
$out .= '<div class="product">';
$out .= '<div class="image">';
$out .= '<img src="' . base_url('asset/img/main/9.jpg') . '" alt="img" class="img-responsive">';
$out .= '<div class="promotion"><span class="discount">' . $row['prod_id'] . '% OFF</span> </div>';
$out .= '</div>';
$out .= '<div class="description"><div class="price"><span>$' . $row['prod_price'] . '</span></div><h4>' . $row['prod_name'] . '</h4>';
$out .= '<p>' . $row['prod_descrip'] . '</p>';
$out .= '</div>';
$out .= '</div>';
if ($counter % 2 == 0 || $length == $counter) {
$out .= '</div>';
}
$counter++;
}
}
return $out;
}
You can use the modulus operator to make the check. If your iterator is a multiple of two it will output the appropriate elements (it does this by checking that the remainder is zero):
public function last_upated_products() {
$data = $this->newest_products_from_db('products');
$out = '';
if ($data) {
$i = 0;
foreach ($data as $k => $row) {
if( ($i % 2) === 0) {
$out .= '<div class="row item">';
}
$out .= '<div class="product">';
$out .= '<div class="image">';
$out .= '<img src="' . base_url('asset/img/main/9.jpg') . '" alt="img" class="img-responsive">';
$out .= '<div class="promotion"><span class="discount">' . $row['prod_id'] . '% OFF</span> </div>';
$out .= '</div>';
$out .= '<div class="description"><div class="price"><span>$' . $row['prod_price'] . '</span></div><h4>' . $row['prod_name'] . '</h4>';
$out .= '<p>' . $row['prod_descrip'] . '</p>';
$out .= '</div>';
$out .= '</div>';
if( ($i + 1) % 2 === 0 || ($i + 1) === count($data) ) {
$out .= '</div>';
}
$i++;
}
}
return $out;
}
Note that the last bit ($i + 1) === count($data) is important in the event that your set holds an uneven number.

how can i make a span element in this line of php

I what to put a span element for $term['nodes']
I have tried to put after bracket and between but nothing works for me
if (isset($term['nodes'])) {
$term['name'] = $term['name'] . ' (' . $term['nodes'] . ')';
}
here is the all functin
function bootstrap_taxonomy_menu_block($variables) {
$tree = $variables['items'];
$config = $variables['config'];
$num_items = count($tree);
$i = 0;
$output = '<ul class="nav nav-pills nav-stacked">';
foreach ($tree as $tid => $term) {
$i++;
// Add classes.
$attributes = array();
if ($i == 1) {
$attributes['class'][] = '';
}
if ($i == $num_items) {
$attributes['class'][] = '';
}
if ($term['active_trail'] == '1') {
$attributes['class'][] = 'active-trail';
}
if ($term['active_trail'] == '2') {
$attributes['class'][] = 'active';
}
// Alter link text if we have to display the nodes attached.
if (isset($term['nodes']))
{
$term['name'] = $term['name'] . ' (<span>' . $term['nodes'] . '</span>)';
}
// Set alias option to true so we don't have to query for the alias every
// time, as this is cached anyway.
$output .= '<li' . drupal_attributes($attributes) . '>' . l($term['name'], $term['path'], $options = array('alias' => TRUE));
if (!empty($term['children'])) {
$output .= theme('taxonomy_menu_block__' . $config['delta'], (array('items' => $term['children'], 'config' => $config)));
}
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
i what this for the bootstrap cdn class , i have move the function on template.php , of drupal theme , but the span element is in plain text in browser
Try this:
if (isset($term['nodes']))
{
$term['name'] = $term['name'] . ' (<span>' . $term['nodes'] . '</span>)';
echo $term['name']; // To see the output
}

Categories