WebsiteBaker Support (2.8.x) > Templates, Menus & Design

menu with images?

<< < (2/2)

crnogorac081:
Here is my suggestion


--- Code: ---// Generate bootstrap menu, instead show_menu2
function bootstrap_menu($array, $current_id = '', $parent_id = 0,$parents = array()){
if($parent_id==0) {
foreach ($array as $element) {
if (($element['parent_id'] != 0) && !in_array($element['parent_id'],$parents)) {
$parents[] = $element['parent_id'];
}
}
}
$menu_html = '';
foreach($array as $element) {
if($element['parent_id']==$parent_id) {
if(in_array($element['id'],$parents)) {
$menu_html .= "\t\t\t\t".'<li class="dropdown'.($current_id == $element['id'] ? ' active': '').'">'."\n";
$menu_html .= "\t\t\t\t\t".'<a'.($element['url'] != '' ? ' href="'.$element['url'].'"' : '').' class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">';
if(file_exists(WB_PATH .'/templates/risk/menu_images/bg-'.$element['id'].'.png')) {
$menu_html .= '<img src="'.WB_URL.'/templates/risk/menu_images/bg-'.$element['id'].'.png" class="zastavice2"/>';
} else {
$menu_html .= '<img src="'.WB_URL.'/templates/risk/menu_images/no_image.png" class="zastavice2"/>';
}
$menu_html .= $element['title'].' <span class="caret"></span></a>'."\t\n";
} else {
$menu_html .= "\t\t\t\t".'<li'.($current_id == $element['id'] ? ' class="active"' : '').'>';
$menu_html .= '<a'.($element['url'] != '' ? ' href="'.$element['url'].'"' : '').'>';
if(file_exists(WB_PATH .'/templates/risk/menu_images/bg-'.$element['id'].'.png')) {
$menu_html .= '<img src="'.WB_URL.'/templates/risk/menu_images/bg-'.$element['id'].'.png" class="zastavice2"/>';
} else {
$menu_html .= '<img src="'.WB_URL.'/templates/risk/menu_images/no_image.png" class="zastavice2"/>';
}
$menu_html .= $element['title'] . '</a>';
}
if(in_array($element['id'],$parents)) {
$menu_html .= "\t\t\t\t\t".'<ul class="dropdown-menu" role="menu">'."\n";
$menu_html .= bootstrap_menu($array, $current_id, $element['id'], $parents);
$menu_html .= "\t\t\t\t\t".'</ul>';
}
$menu_html .= '</li>'."\n";
}
}
return $menu_html;
}

// Fetch menu items from base, note that all pages are public available.
$menu_items = array();
$qm = $database->query("SELECT * FROM `".TABLE_PREFIX."pages` ORDER BY position ASC");
if ($qm->numRows() > 0) {
while ($l = $qm->fetchRow()) {
if ($l['link'] != '') { $link = WB_URL.$l['link']; } else { $link = '';}
$menu_items[] = array("id" => $l['id'], "parent_id" => $l['parent'], "title" => $l['title'], "url" => $link );
}
}

$menu = bootstrap_menu($menu_items, PAGE_ID);
echo '
<ul class="sf-menu">
'.menu.'
</ul>';

--- End code ---

Images should be under ROOT/templates/risk/menu_images/bg-XXX.png where XXX is PAGE_ID number

Navigation

[0] Message Index

[*] Previous page

Go to full version