Forum

Thread tagged as: Question, Configuration, Discussion

Split navigation unordered list into multiple lists

Hi there,

I have a navigation groups for the footer of a site I'm working on. This is great because my user can add pages to it themselves. However I only want 5 items before a new list begin - as this fits with my design and they are unlikely to add many more than 12.

So..

I got thinking that if I could find a way to retrieve the nav item I could then do some sort of loop and count. This is my effort so far:

<?php
  $navigation = perch_pages_navigation(array(
      'skip-template' => true,
      'levels' => 1
  ));

  $number = 0;

  // Now let's loop through the perch content in the project page template
  foreach( $navigation as $item ) {

      // Add Skip template so we can use the data
      $opts = array(
      'page' => $item['pagePath'], // This is where we use the data from the nav list to get each page in turn
      'skip-template' => true
      );

      echo '<ul>';
        for( $opts = 1; $opts <= 6; $opts++ )
        {
            echo '<li>';
            echo $item['pagePath'];
            echo '</li>';
            if( $opts % 5 == 0 )
            {
                echo '</ul><ul>';
            }
        }
        echo '</ul>';
  }

?>

This repeats the /index.php over and over as I think I'm basically just iterating over the navigation five times. Instead of having the navigation variable am I right in thinking I need a variable that just stores the items within the navigation and loops through those? Because I'm sort of getting the page URL but that nav variable is all wrong. Now I'm just in a muddle.

My logic might be off so looking for guidance and any tips of how I can retrieve a variable of the pages within the navigation.

If more info is needed or I'm not clear enough, let me know.

Mathew Doidge

Mathew Doidge 2 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Had you considered using <perch:every> tags in the navigation template?

Drew McLellan said:

Had you considered using <perch:every> tags in the navigation template?

Oh my! Sorry Drew, I had completely overlooked the every tag. Amazing - I was over complicating things all along. Thank you!