Menu with parents/child of static pages

Post Reply
TheBuzzDee
Jr. Bludit
Posts: 1
Joined: Thu Nov 04, 2021 11:51 am
Been thanked: 1 time

Hi,

I am using the "editorial"-theme https://github.com/bludit-themes/editorial and I want to write a plugin where the original navigation of the editorial-theme is used in the sidebar.

Take a look here https://html5up.net/uploads/demos/edito ... ments.html and you see that originally the childs of a (parent) page are toggled with a down-arrow and shown as a submenu.

The original markup for this is:

Code: Select all

<nav id="menu">
	<header class="major">
	<h2>Menu</h2>
	</header>
	
	<ul>		
	<li>
		<span class="opener">Submenu</span>
		<ul>
			<li><a href="#">Lorem Dolor</a></li>
			<li><a href="#">Ipsum Adipiscing</a></li>
		</ul>
	</li>
	
	
	<li><a href="#">Etiam Dolore</a></li>
	<li><a href="#">Adipiscing</a></li>
	</ul>
	
</nav>
I can't build this markup with my plugin-code, maybe you can help ?
Here's the code of the whole plugin so far

Code: Select all

<?php

class pluginMyNavigation extends Plugin {

	public function init()
	{
		// Fields and default values for the database of this plugin
		$this->dbFields = array(
			'label'=>'Static Pages',
			'homeLink'=>true
		);
	}

	// Method called on the settings of the plugin on the admin area
	public function form()
	{
		global $L;

		$html  = '<div class="alert alert-primary" role="alert">';
		$html .= $this->description();
		$html .= '</div>';

		$html .= '<div>';
		$html .= '<label>'.$L->get('Label').'</label>';
		$html .= '<input id="jslabel" name="label" type="text" value="'.$this->getValue('label').'">';
		$html .= '<span class="tip">'.$L->get('This title is almost always used in the sidebar of the site').'</span>';
		$html .= '</div>';

		$html .= '<div>';
		$html .= '<label>'.$L->get('Home link').'</label>';
		$html .= '<select name="homeLink">';
		$html .= '<option value="true" '.($this->getValue('homeLink')===true?'selected':'').'>'.$L->get('Enabled').'</option>';
		$html .= '<option value="false" '.($this->getValue('homeLink')===false?'selected':'').'>'.$L->get('Disabled').'</option>';
		$html .= '</select>';
		$html .= '<span class="tip">'.$L->get('show-the-home-link-on-the-sidebar').'</span>';
		$html .= '</div>';

		return $html;
	}

	// Method called on the sidebar of the website
	public function siteSidebar()
	
	
	{
		

		
		
	$html   = '<nav id="menu">';
	
	
	$label = $this->getValue('label');
	if (!empty($label)) {
	$html  .= '	<header class="major">';
	$html  .= '	<h2>'.$label.'</h2>';
	$html  .= '	</header>';
	}
	
	$html  .= '	<ul>';	


	$staticPages = buildStaticPages();
	
	foreach ($staticPages as $page) { //START FORAECH
		
	
	$html  .= '<li>';
	
	if ($page->hasChildren()) {
	$html  .= '<span class="opener">';	
	$html  .= '<a href="' . $page->permalink(FALSE) . '">' . $page->title() . '</a>';
	$html  .= '</span>';
	} 
	
	
	if (!$page->hasChildren()) {	
	$html  .= '<a href="' . $page->permalink(FALSE) . '">' . $page->title() . '</a>';	
	}
	
	$html  .= '</li>';

		
		
	
	} //END FOREACH
	
	
	
	
	
	$html  .= '	</ul>';	
	$html  .= '</nav>';
		
		
	return $html;	
	}
	
	
	
	
	
	

}
The essential part ist inside public function siteSidebar() where all the static pages are put together and nested, depending if they have childs, or are parents or whatever.... I'm really getting into trouble to do this!

Could you please help me to get this working ?

Thanks a lot,
TheBuzzDee
Bernie
Ssr. Bludit
Posts: 11
Joined: Wed Sep 15, 2021 12:37 pm
Been thanked: 7 times

Hello TheBuzzDee,

a plugin is not required. Just make the change in the theme.
I done it allready in a own theme.

with regards
Bernd
Bernie
Ssr. Bludit
Posts: 11
Joined: Wed Sep 15, 2021 12:37 pm
Been thanked: 7 times

Menu with submenus for the theme "Editorial" with static pages

Demo
https://themes.bludit.net/editorial/

Replace the sidebar.php file in the "/bl-themes/editorial-2.5/php/" folder with the file in the attachment.

This file has the following content:

Code: Select all

<!-- Menu -->
<nav id="menu">
	<header class="major">
		<h2><?php echo $language->get('Menu'); ?></h2>
	</header>
	<ul>
		<li><a href="<?php echo Theme::siteUrl(); ?>"><?php echo $language->get('Homepage'); ?></a></li>
		<?php foreach ($staticContent as $staticPage): ?>
		<?php if (!$staticPage->hasChildren() and !$staticPage->isChild()) { ?>          
		<li><a href="<?php echo $staticPage->permalink(); ?>"><?php echo $staticPage->title(); ?></a></li>        
		<?php } ?>
		<?php if ($staticPage->hasChildren()) { ?>
		<li><span class="opener"><?php echo $staticPage->title(); ?></span>
			<ul>
				<?php $children = $staticPage->children();
				if ($site->orderBy() === 'date') {$children = array_reverse($children);}
				foreach ($children as $child) { ?>
				<li><a href="<?php echo $child->permalink(); ?>"><?php echo $child->title(); ?></a></li>
				<?php } ?>
			</ul>
		</li>
		<?php } ?>
		<?php endforeach ?>
	</ul>
</nav>

<?php Theme::plugins('siteSidebar') ?>

<!-- Footer -->
<footer id="footer">
        <p class="copyright"><?php echo $site->footer() ?><br>Design: <a href="https://html5up.net">HTML5 UP</a><br>Powered by <a href="https://www.bludit.com">BLUDIT</a></p>
</footer>
Example:
You want to create a submenu with the name "Fashion" and the subpages "Men" and Woman".

Create a static page with the name "Fashion". Under "SEO" set the page to "noindex" so that the page is not entered in the sitemap. We only need the name of the page as a menu item here.

Create 2 more static pages with the names "Men" and Woman". Enter the page "Fashion" for both pages under "Parents".
Attachments
sidebar.php.zip
Unzip and replace with original file
(660 Bytes) Downloaded 97 times
Post Reply