[Solved] Bludit 2: How to build a horizontal navigation?

Post Reply
User avatar
Torsten_Kelsch
Legend Bludit
Posts: 263
Joined: Thu Aug 27, 2015 10:24 pm
Location: Germany
Has thanked: 4 times
Been thanked: 2 times
Contact:

Hello,

in Bludit 2.0.2, I’d like to have a horizontal navigation for the static pages in my self-made theme, but I don’t know how to build it. My code is as follows:

Code: Select all

<ul>
	<li><a href="<?php echo $Site->homepage(); ?>">Start</a></li>
	<?php
		foreach($pages as $page) {
			echo '<li ';
			if( $WHERE_AM_I=='page') {echo 'class="active"';}
			echo '><a href="'.$page->permalink().'">'.$page->title().'</a></li>';	
		}	
	?>		
</ul>
But this does not show all existing static pages, only the home page and the page which I’m currently visiting. The

Code: Select all

if( $WHERE_AM_I …
is only there to mark the active page; leaving it out does not make the other pages appear in the menu. There must be something wrong with the variables. I could not find anything helpful in the docs. but something like the code above used to work under Bludit 1, but no longer works under Bludit 2, as it seems.

Any ideas? Thanks in advance.
Last edited by Torsten_Kelsch on Wed Nov 08, 2017 2:09 pm, edited 2 times in total.
On Error GoTo Bed
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

The theme Log has a horizontal navigation for static content. You can copy the code.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
User avatar
Torsten_Kelsch
Legend Bludit
Posts: 263
Joined: Thu Aug 27, 2015 10:24 pm
Location: Germany
Has thanked: 4 times
Been thanked: 2 times
Contact:

Edi wrote: Tue Nov 07, 2017 10:09 pm The theme Log has a horizontal navigation for static content. You can copy the code.
Oh, cool, thank you. I will try that.
On Error GoTo Bed
User avatar
Torsten_Kelsch
Legend Bludit
Posts: 263
Joined: Thu Aug 27, 2015 10:24 pm
Location: Germany
Has thanked: 4 times
Been thanked: 2 times
Contact:

Now it works. I extended the code from the theme Log a bit so that it fits my needs. And here’s my code:

Code: Select all

<ul>
	<?php
		function umlaute($string) {
			$search = array("Ä", "Ö", "Ü", "ä", "ö", "ü", "ß", "´");
			$replace = array("Ae", "Oe", "Ue", "ae", "oe", "ue", "ss", "");
			return str_replace($search, $replace, $string);
		}

		foreach ($staticPages as $staticPage) {
			if($_SERVER['REQUEST_URI'] == "/".strtolower(umlaute($staticPage->title()))) {
				echo '<li class="active"><a href="'.$staticPage->permalink().'">'.$staticPage->title().'</a></li>';
			} else {
				echo '<li><a href="'.$staticPage->permalink().'">'.$staticPage->title().'</a></li>';
			}
		}
	?>
</ul>
A little explanation:
The function changes German umlauts to normal characters. In the loop, it is checked on which page the user currently is. In case that the page title has umlauts in it, they are changed to normal letters, and also the letters are changed to lowercase, so that the title is exactly the same as the request uri. Now this page is marked as active in the navigation (via CSS). All other pages remain unmarked.
On Error GoTo Bed
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

Thank you for sharing your solution!
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
User avatar
Torsten_Kelsch
Legend Bludit
Posts: 263
Joined: Thu Aug 27, 2015 10:24 pm
Location: Germany
Has thanked: 4 times
Been thanked: 2 times
Contact:

Edi wrote: Wed Nov 08, 2017 2:13 pm Thank you for sharing your solution!
You’re welcome. But I have an off topic question: How can I mark my thread as solved, except to change the first title? Or are only the forum admins able to do this?
On Error GoTo Bed
Post Reply