#1 2015-05-19 16:13:02

Dp.hermes
Member
From: Paris - France
Registered: 2013-07-05
Posts: 47

[Solved] Problem with the navigation helper

Hello there !

I'm on my way to finish a website with Ionize but I have a little problem.

The navigation I developed is a bit more complex than usual.
I found a way to implement the pages menu with the Ionize admin but my nav doesn't appear the way I want.

To reach my goal I would simply need to delete the first <ul> built by the navigation_helper.
So it has to be only something like :
    <li><a>Link 1</a></li>
    <li><a class="mn-has-sub">Link 2</a>
          <ul class="mn-sub">
                <li><a>Sublink 1</a></li>
                <li><a>Sublink 2</a></li>
          </ul>
    </li>

Unfortunately, the way I tried to change it deletes all the <ul> normally generated for the submenus.

Here's the code for the tree_navigation I actually have.
Reminder : Except if I did something wrong, deleting or changing this line doesn't work :
$tree = '<ul' . $id . $dropdown_ul_class . '>';

Thank you very much for your help !!


if( ! function_exists('get_tree_navigation'))
{
	function get_tree_navigation($items, $id = NULL, $class = NULL, $first_class = NULL, $last_class = NULL, $dropdown_ul_class = NULL)
	{
		// HTML Attributes
		$id = ( ! is_null($id) ) ? ' id="' . $id . '" ' : '';
		$class = ( ! is_null($class) ) ? ' class="' . $class . '" ' : '';
		$dropdown_ul_class = ( ! is_null($dropdown_ul_class) ) ? $dropdown_ul_class : $class;
				
		$tree = '<ul' . $id . $dropdown_ul_class . '>';
		
		foreach($items as $key => $page)
		{
			if ($key !== 'articles')
			{
				$class = array();
				
				$dropdown_ul_class = (!empty($page['children'])) ? ' class="mn-sub"' : '';				
		
				if (( ! empty($page['active_class']))) $class[] = $page['active_class'];
				if ($key == 0 && ! is_null($first_class)) $class[] = $first_class;
				if ($key == (count($items) - 1) && ! is_null($last_class)) $class[] = $last_class;
				if (!empty($page['children'])) $class[] = 'mn-has-sub';
                if (!empty($page['children']) && $page['id_parent'] != 0) $class[] = 'dropdown-submenu';
				if ($page['home'] == 1) $class[] = 'home';
                $icon = (!empty($page['ion_class'])) ? '<i class="icon-fixed-width icon-'.$page['ion_class'].'"></i> ' : '';
				// trace($page);
				// $class = ( ! empty($class)) ? ' ' . implode(' ', $class) . '' : '';
				$class = ( ! empty($class)) ? ' class="'.implode(' ', $class).'"' : '';

				$title = ($page['nav_title'] != '') ? $page['nav_title'] : $page['title'];
				
				$tree .= '<li>';
				$tree .= '<a ' . $class . ' href="' . ((!empty($page['children'])) ? '#' : $page['absolute_url']) . '">' . $icon . $title . ((!empty($page['children']) && $page['id_parent'] == 0) ? '' : '') . ' </a>';
		
				if (!empty($page['children']))
					 $tree .= get_tree_navigation($page['children'], NULL, $class, NULL, NULL, $dropdown_ul_class);
				
	
				if (!empty($page['articles']))
				{
					$tree .= '<ul' . $id . $class . $dropdown_ul_class . '>';
					
					foreach($page['articles'] as $article)
					{
						$class = array();
						if (( ! empty($article['active_class']))) $class[] = $article['active_class'];
						if ($key == 0 && ! is_null($first_class)) $class[] = $first_class;
						if ($key == (count($page['articles']) - 1) && ! is_null($last_class)) $class[] = $last_class;
						
						$class = ( ! empty($class)) ? ' class="'.implode(' ', $class).'"' : '';

						$tree .= '<li'.$class.'><a'.$class.' href="' . $article['url'] . '">'.$article['title']. '</a></li>';
					}
					$tree .= '</ul>';
				}
				
				
				$tree .= '</li>';
			}
		}

		if ( ! empty($items['articles']))
		{
			foreach($items['articles'] as $article)
			{
				$class = array();
				if (( ! empty($article['active_class']))) $class[] = $article['active_class'];
				if ($key == 0 && ! is_null($first_class)) $class[] = $first_class;
				if ($key == (count($items['articles']) - 1) && ! is_null($last_class)) $class[] = $last_class;
						
				$class = ( ! empty($class)) ? ' class="'.implode(' ', $class).'"' : '';

				$tree .= '<li'.$class.'><a'.$class.' href="' . $article['url'] . '">'.$article['title']. '</a></li>';
			}
		}
		
		$tree .= '</ul>';

		return $tree;
	}
}

Last edited by Dp.hermes (2015-11-30 19:30:56)

Offline

#2 2015-05-23 01:06:42

otemu
Member
Registered: 2014-03-07
Posts: 183

Re: [Solved] Problem with the navigation helper

Hi,

Updated the tree function and seems to work with what your trying to achieve, please note that I am using ionize 1.0.5 so hopefully work with whatever version of inoize you are using

if( ! function_exists('get_tree_navigation'))
{
	//do not set ul tag for first time
	function get_tree_navigation($items, $id = NULL, $class = NULL, $first_class = NULL, $last_class = NULL, $removeUl = true)
	{
		// HTML Attributes
		$id = ( ! is_null($id) ) ? ' id="' . $id . '" ' : '';
		$class = ( ! is_null($class) ) ? ' class="' . $class . '" ' : '';

		//here we remove the first ul tag
		if($removeUl){  
			$removeUl = false; 
			$tree = '';
		}else{
			$tree = '<ul' . $id . $class . '>';
		} 

		foreach($items as $key => $page)
		{
			//determine if last item
			$numItems = count($items);
			$lastItem = false;
			$i = 0;
			if(++$i === $items) {
				$lastItem = true;
			}
			if ($key !== 'articles')
			{
				$class = array();
				if (( ! empty($page['active_class']))) $class[] = $page['active_class'];
				if ($key == 0 && ! is_null($first_class)) $class[] = $first_class;
				if ($key == (count($items) - 1) && ! is_null($last_class)) $class[] = $last_class;
				
				$class = ( ! empty($class)) ? ' class="'.implode(' ', $class).'"' : '';

				$title = ($page['nav_title'] != '') ? $page['nav_title'] : $page['title'];
				
				$tree .= '<li'.$class.'><a'.$class.' href="' . (($page['has_url'] != 0) ? $page['absolute_url'] : '#') . '">'.$title. '</a>';
		
				if (!empty($page['children']))
					//now we can add the ul for submenu
					 $tree .= get_tree_navigation($page['children'], $id = NULL, $class = NULL, $first_class = NULL, $last_class = NULL, $removeUl = false);
				
	
				if (!empty($page['articles']))
				{
					$tree .= '<ul' . $id . $class . '>';
					
					foreach($page['articles'] as $article)
					{
						$class = array();
						if (( ! empty($article['active_class']))) $class[] = $article['active_class'];
						if ($key == 0 && ! is_null($first_class)) $class[] = $first_class;
						if ($key == (count($page['articles']) - 1) && ! is_null($last_class)) $class[] = $last_class;
						
						$class = ( ! empty($class)) ? ' class="'.implode(' ', $class).'"' : '';

						$tree .= '<li'.$class.'><a'.$class.' href="' . $article['url'] . '">'.$article['title']. '</a></li>';
					}
					$tree .= '</ul>';
				}
				
				
				$tree .= '</li>';
			}
		}

		if ( ! empty($items['articles']))
		{
			foreach($items['articles'] as $article)
			{
				$class = array();
				if (( ! empty($article['active_class']))) $class[] = $article['active_class'];
				if ($key == 0 && ! is_null($first_class)) $class[] = $first_class;
				if ($key == (count($items['articles']) - 1) && ! is_null($last_class)) $class[] = $last_class;
						
				$class = ( ! empty($class)) ? ' class="'.implode(' ', $class).'"' : '';

				$tree .= '<li'.$class.'><a'.$class.' href="' . $article['url'] . '">'.$article['title']. '</a></li>';
			}
		}
		
		//don't end closing ul if last item
		$lastItem? '' : $tree .= '</ul>';

		return $tree;
	}
}

Let me know if that works, also commented the code

Offline

#3 2015-11-30 19:23:36

Dp.hermes
Member
From: Paris - France
Registered: 2013-07-05
Posts: 47

Re: [Solved] Problem with the navigation helper

Forgot to answer your post.
It works, so thanks for the tip.

Topic solved ! wink

Offline

What's Ionize ?

Ionize is an Open Source Content Management System created by webdesigners for webdesigners.

Created and maintained by Partikule and Toopixel, Ionize wants to be the easiest and most powerful CMS.

Can I help ?

Because talent is nothing without involvement, we are looking for motivated coders and webdesigners to join the project team.

Resources

Website : ionizecms.com
Documentation : doc.ionizecms.com

Development : Ionize on GitHub
Translations : Ionize Translations