1

first off, i’m using Adaptive Theme so maybe this won’t make sense using a different theme. but here i want to add a class to

<header id=“main-content-header” class="someclasses">

which is found in page.tpl but based on node id. this would have to be done in mysubtheme_preprocess_page(). i have part of the code working.

 $variables['content_header_attributes_array']['class'][] = 'about' 

but don’t know how to ascertain the node id that is contained on the page. is it possible? my pseudo code would read something like

if (nodeId == 1){
 $variables['content_header_attributes_array']['class'][] = 'about'
} 

by the way, i find myself needing to do this constantly so i can style these headers differently, at least for this project i do. maybe there’s a better way to accomplish,..?

i can use conditional stylesheets but then there’s the issue of adaptive design and you’d have to put media query’s in these conditional stylesheets. don’t know if that’s such a good idea or not.

  • 2
    @samuelsov is right. But to get node id you can do this: $node = menu_get_object(); if ($node) { // use $node->nid} – J. Reynolds Oct 21 '14 at 4:23
5

You probably already have a specific class for the page on the <body> tag.

For example :

<body class="html not-front not-logged-in page-node page-node- page-node-5 node-type-page">

Then a css should work for you :

body.page-node-5 #main-content-header { ... }

or

body.node-type-page #main-content-header { ... }
  • yes thanks, good point but i really want to get under the hood w/ the PHP and process & preprocess functions – TopTomato Oct 22 '14 at 3:27
  • but that is a very good answer, thank you – TopTomato Oct 22 '14 at 3:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.