Forum
Set parent page to 'active' when using perch_content_custom
In an effort to streamline the editing process for a site's end-users (differing degrees of computer literacy etc.), I'm using an area with multiple items allowed in conjunction with perch_content_custom
to output content for a specific page.
This page (project.php) exists outside of the Perch interface, and pulls in content like so:
<?php include($_SERVER['DOCUMENT_ROOT'].'/_includes/header.php');?>
<?php
$project = perch_content_custom('Projects', array(
'page'=>'/work/index.php',
'template'=>'project.html',
'skip-template'=>'false',
'filter'=>'project_slug',
'match'=>'eq',
'value'=>$_GET['p'],
'return-html'=>'true'
));
print($project['html']);
?>
<?php include($_SERVER['DOCUMENT_ROOT'].'/_includes/footer.php');?>
The page lives inside the 'work' directory, and its index page is where new items are added. The index page displays a cut-down version of this content, again using perch_content_custom
.
I'm using .htaccess
rewrite rules to map domain.com/work/project_slug
to domain.com/work/project.php?p=project_slug
. This works fine.
What I'd like to do is set the 'Work' item in the main navigation as active (as it would be if I was using subpages). Is there a way to do this with Perch, or do I need to set up a different header file with the 'Work' item manually set as active?
I take it that by "outside the Perch interface" you mean that the project pages aren't in Perch's pages list, right?
In Perch you could add project.php to the Pages list (as a subpage of Work) and set it to hide from the navigation. Then it will be "known" by Perch and can affect the navigation listings/highlighting.
Alternatively, I sometimes employ a simple jQuery solution for such situations so different header files aren't needed. The "special nav cases" code may do the trick if you add in your
"/work"
case.Note that the first bit adds the classes to the
<a>
tags and the second adds them to the<li>
tags. Adjust for your needs.Have you tried telling Perch what you want the page to be?
Ah, that did it - thanks Drew.