EllisLab text mark
Advanced Search
     
Structure Entries showing sub menus
Posted: 26 June 2012 03:15 PM   [ Ignore ]
Joined: 2011-09-07
4 posts

Hi All

I have been looking for a way to show the first level navigation and the sub nav for the page you are current on (second level).

For example if the whole nav looks like:
Home
About Us
  Who is in the team
  Personal Bio
Interesting Facts
  Interesting Fact 1
  Interesting Fact 2
Contact us

But I am in ‘Who is in the team’ and I want to show :

Home
About Us
  Who is in the team*
  Personal Bio
Interesting Facts
Contact us

I have come up with the following solution, but would be grateful if anyone has a better solution.


{exp:structure_entries depth=“2”}
{if {depth} == 1}{title}
{/if}
<?php
$segArray = “{page_uri}”;
$segArray = explode(”/”, $segArray);
if (($segArray[3] == “{segment_1}”) && ($segArray[4] !== “”)) echo “<li>{title}</li>”;
?>
{/exp:structure_entries}

Thanks in advance

Dan

 
Posted: 27 June 2012 10:16 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2007-06-27
12 posts

Hi danbrinnand. Have you tried the built in functionality of the Structure nav tag? By default it displays a list with a nested ul inside of the parent selection and should have the functionality that you are looking for. There is a good deal of flexibility in styling the parent ul and the nested ul. You may want to take a look at the here and parent-here classes that it adds to the li’s.

 
Posted: 27 June 2012 10:28 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2011-09-07
4 posts

Hi Summer Student

Thanks for your reply. Yes I had tried this, however I needed to declare my class within the a tag as I need to change the whole a block on rollover.

Regards

Dan

 
Posted: 28 June 2012 10:14 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2007-06-27
12 posts

It looks like you are using PHP to explode the uri segments, but those are already available in EE as {segment_1} {segment_2} and so on. So you may not need to use PHP at all.

Sometimes using structure entries is necessary, but more often than not you can accomplish the same thing with a little styling - Using CSS selectors to target different elements and style them accordingly. Have you checked out these options for the nav tag?

Add Level Classes
add_level_classes=“yes|no”, defaults to no
Displays class=“sub_level_0”, class=“sub_level_1”, etc on each li

Add Unique IDs
add_unique_ids=“yes|entry_id|no”, defaults to no
Adds a unique ID to the a tag using the top parent slug, default seperator and pageslug or entry ID.