Static Pages in Navigation Bar

Post Reply
vela025
Jr. Bludit
Posts: 3
Joined: Thu Dec 17, 2020 4:18 pm

Hi,

Following my previous post i decided to forego the testing stage and just put bludit on my paid host, which is working great.

I'm struggling with the navigation bar in the blog X, andy and alternative themes. I only want to be able to see top level pages in the navigation bar (I think I'm having the same issue as this user viewtopic.php?t=1756 . Unlike that user I don't need levels 3+ just Parent and Child.

For example if I have the following pages and structure:

---Reviews
+book1
+book2
+book3
---Camping
+trip1
+trip2
+trip3

I only want the navigation bar to show Reviews and Camping, not all the other Child pages.

I have a semi solution of changing Reviews and Camping to default (rather than static), setting all there related pages as children, and then going back to the reviews and camping pages and changing the page type back to static, but this seems a bit impractical to do each time I add more content.

I can't see a plugin that achieves this, I do have the more levels plugin installed but do not think that it is currently working. However did find something in the documentation about this (but now have lost the page :? , would I need to edit the php file?).

The theme I would like to use is Blog X, but I am willing to use any that solve this problem is anyone has any recommendations? Is this achievable using Bludit pro?

Cheers!
User avatar
Jay
Master Bludit
Posts: 133
Joined: Mon Feb 11, 2019 8:41 pm

Blogx generates menu using $staticPage variable, thus all nested static pages will be shown in menu.
Check the print navigation bar section in docs
https://docs.bludit.com/en/dev-snippets ... d-subpages

and use the snippet without the children part in conditional code
quicklyweb
Jr. Bludit
Posts: 8
Joined: Wed Dec 16, 2020 12:32 pm

in navbar.php of BLOGX theme

Below code shows the static pages and child as dropdown

Code: Select all

foreach ($staticContent as $staticPage) {
	$children = $staticPage->children();
	if (!$staticPage->isChild())
	{
		

			if ($staticPage->hasChildren())
			{
			    echo '<li class="nav-item dropdown">';
		         echo '<a class="nav-link dropdown-toggle" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" href="'. $staticPage->permalink().'">'.$staticPage->title().'</a>';

				echo PHP_EOL.'<div class="dropdown-menu" aria-labelledby="navbarDropdown">'.PHP_EOL;
				foreach ($children as $child) 
				{
					echo '<a class="dropdown-item" href="'.$child->permalink().'">'.$child->title().'</a>'.PHP_EOL;
				}
				echo '</div>'.PHP_EOL;
			} else {
			    echo '<li class="nav-item">';
	        	echo '<a class="nav-link" href="'. $staticPage->permalink().'">'.$staticPage->title().'</a>';
	}
		echo '</li>'.PHP_EOL;
	}
}
But if you don't want to show childs in dropdown just modify the code as below as below

in navbar.php of BLOGX theme

Below code shows the static pages and child as dropdown

Code: Select all

foreach ($staticContent as $staticPage) {
	$children = $staticPage->children();
	if (!$staticPage->isChild())
	{
			if ($staticPage->hasChildren())
			{
			    echo '<li class="nav-item dropdown">';
		         echo '<a class="nav-link"" href="'. $staticPage->permalink().'">'.$staticPage->title().'</a>';
			} else {
			    echo '<li class="nav-item">';
	        	echo '<a class="nav-link" href="'. $staticPage->permalink().'">'.$staticPage->title().'</a>';
	}
		echo '</li>'.PHP_EOL;
	}
}
BLUDIT HOSTING QUICKLYWEBImage

SEE BLUDIT IN ACTION @ QUICKLYWEB
http://www.quicklyweb.com
User avatar
RalfKerkhoff
Sr. Bludit
Posts: 35
Joined: Sun Jan 03, 2021 11:16 am
Location: Germany
Has thanked: 1 time
Contact:

Hi Guys,

any hints/tips how to get this working in the Bluma Template?

The code works fine with the BlogX template, but I can not get it working with the Bluma theme.

Any hints are welcome.

cheers
ralf
User avatar
Jay
Master Bludit
Posts: 133
Joined: Mon Feb 11, 2019 8:41 pm

RalfKerkhoff wrote: Sun Jan 03, 2021 11:18 am Hi Guys,

any hints/tips how to get this working in the Bluma Template?

The code works fine with the BlogX template, but I can not get it working with the Bluma theme.
This is basically a snippet I prepared, and posted some time ago, as the default menu snippet shown in docs stopped working in latest bludit version. At least for me.
Check the thread here: viewtopic.php?f=6&t=1894&p=9039

I won't be even able to reproduce your problem as you'd need to provide more information about errors you are experiencing.
First step is always towards showing php errors. You can find in docs how to do it.
I suppose that developer of template you mentioned used different variables to get pages data.
User avatar
RalfKerkhoff
Sr. Bludit
Posts: 35
Joined: Sun Jan 03, 2021 11:16 am
Location: Germany
Has thanked: 1 time
Contact:

Hi,
thanks for the snippets. The css part will be helpful.

Cheers
Ralf
Post Reply