Forum

Thread tagged as: Question, Problem, Configuration

Listing pages with perch_pages_navigation() isn't showing pages

We're using the current location of the user to display a list of pages. In the directory we have a "subnav.php" file with the following:

<?php
function getNavPath() {
  $path_parts = explode('/', $_SERVER['REQUEST_URI']);
  $path_sections = array();
  foreach ($path_parts as $part) {
    if($part !== '' && strpos($part, '.php') === false) {
      $path_sections[] = $part;
    }
  }
  $path_sections = array_slice($path_sections, 0, 3);
  return '/'.implode('/', $path_sections).'/';
}

perch_pages_navigation(array(
  'hide-extensions' => true,
  'include-parent' => true,
  'levels' => 2,
  'from-path'=> getNavPath(),
  'template' => array('interior.html', 'basic-item.html')
));

?>

the code that displays the list is:

<perch:before>
  <ul>
</perch:before>
    <li><a href="<perch:pages id="pagePath" />" ><perch:pages id="pageNavText" /></a></li>
<perch:after>
  </ul>
</perch:after>

This works in one directory perfectly fine but when placed in another directory (with the same number of levels) it doesn't work. for example:

"mysite.com/library/books" - works "mysite.com/library/magazines" - doesn't work

It's acting like no pages exist in the directory when literally the same pages were copied into the directory (they all used shared regions).

David Powell

David Powell 0 points

  • 3 years ago

If I change $path_sections = array_slice($path_sections, 0, 3); to 2 it'll show pages from the previous directory.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm afraid I can't help you debug your own code.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello David,

It would be wise to start by hardcoding the value of from-path and see if you get what you expect. Then progress to setting the value dynamically.

Hussein Al Hammad said:

Hello David,

It would be wise to start by hardcoding the value of from-path and see if you get what you expect. Then progress to setting the value dynamically.

I tried that and I get the same result. It's as though it doesn't see the directory. I've checked permissions and ownership.

Drew McLellan said:

I'm afraid I can't help you debug your own code.

That's fair but the code works in one directory but not the other...

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you give an example with hardcoded paths?