Hi there,
Here's the situation:
I've got a basic navigation using the primary links. Now one of them is a book, it's called Help.
My goal is it to mark Help as active on any page of that book (even when using aliases).
I tried to find something on this site about my issue. I did find some questions on it ... and solutions that didn't really work (for me), partly because I want to use path aliases, too. So I wrote the following code:
/* extracts the string between the first and second ", eg adams_extract_path('<a href="pathurl">pathname</a>') returns "pathurl" */
function adams_extract_path($link) {
$path = substr(stristr($link, '"'),1);
$pathlen = strlen($path)-strlen(stristr($path, '"'));
return substr($path, 0, $pathlen);
}
/* returns true if and only if $child is a substring of $parent */
function adams_ischild($parent, $child) {
return (substr_count($parent, $child) > 0);
}
/* returns true if the path in $link is a substring of $breadcrumb */
function adams_isactive($link, $breadcrumb) {
$path = adams_extract_path($link);
return (substr_count($link, 'active') > 0) || adams_ischild($breadcrumb, $path);
}
Now in my page.tlp.php I do something like:
foreach ($primary_links as $link):
- if (adams_isactive($link, $breadcrumb)) print 'class="active"' ">
print $link
endforeach;