Forum
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).
If I change
$path_sections = array_slice($path_sections, 0, 3);
to2
it'll show pages from the previous directory.I'm afraid I can't help you debug your own code.
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.
That's fair but the code works in one directory but not the other...
Can you give an example with hardcoded paths?