Okay, I figured out a method on my own that I think works better after re-reading the theme guide. I’ll document it here.
In your custom theme’s main plugin file (YourThemePlugin.inc.php), add this to your init():
HookRegistry::register ('TemplateManager::display', array($this, 'loadTemplateData'));
Now create your loadTemplateData function. This will add the necessary classes for your body element.
public function loadTemplateData($hookName, $args) {
// Retrieve the TemplateManager and the template filename
$templateMgr = $args[0];
//$template = $args[1];
$requestedOp = $templateMgr->get_template_vars('requestedOp');
$requestedPage = $templateMgr->get_template_vars('requestedPage');
$issue = $templateMgr->get_template_vars('issue');
$isCurrentIssue = 0;
if ($issue) {
$isCurrentIssue = $issue->getCurrent();
}
// If the current issue...
if ( $requestedOp && $requestedPage && $isCurrentIssue ) {
$bodyClass = $requestedOp . '-' . $requestedPage . '-current';
} elseif ( $requestedOp && $requestedPage ) {
$bodyClass = $requestedOp . '-' . $requestedPage;
} else {
$bodyClass = $requestedOp;
}
$templateMgr->assign(array(
'bodyClass' => $bodyClass,
));
}
In your template’s header.tpl, replace the <body>
tag with:
<body class="{$bodyClass}">
This worked well for me and keeps it in the theme rather than a plugin or something.
In my CSS, I did this:
// Highlight the current page
.index-about .nmi_type_about .nav-link, .view-issue-current .nmi_type_current .nav-link, .view-article-current .nmi_type_current .nav-link, .archive-issue .nmi_type_archives .nav-link, .view-issue .nmi_type_archives .nav-link, .view-article .nmi_type_archives .nav-link, .submissions-about .nmi_type_submissions .nav-link, .editorialTeam-about .nmi_type_editorial_team .nav-link, .contact-about .nmi_type_contact .nav-link { {
background-color: #fff;
color: #000;
}
For clarification, I am using a child theme I made of the healthSciences theme, which uses Bootstrap 4. You should adjust your CSS above accordingly to match the menu structure of your theme.