I seem to remember an older version of basic providing page specific body classes.
This comes in super-handy for page specific styling, obviously.

Am I dreaming or what?

Comments

austintnacious’s picture

Any suggestions about how I could insert a NID into the body classes?

I'm not a programmer! And I don't want to have to do it with templates / template suggestions

I see the code for template suggestions based on NID in template.php and I'm wondering if anyone has some code for NID based body classes.

With Basic 2.4 I do get body.page-node which is not very useful since it doesn't narrow anything down.
And I get body.node-type-[content-type] which is useful but I still want to be more specific . . .

Anyone?

austintnacious’s picture

OK! so I guess I screwed up by working with version 2.4

I enabled basic 2.5 on my system and the page specific body classes are there, as are the wireframes and registry rebuild theme settings.

I now see the following section in Basic 2.4's template.php

if (!$vars['is_front']) {
    // Add unique classes for each page and website section
    $path = drupal_get_path_alias($_GET['q']);
    list($section, ) = explode('/', $path, 2);
    $body_classes[] = basic_id_safe('page-'. $path);
    $body_classes[] = basic_id_safe('section-'. $section);

But for whatever reason that routine isn't working on my site. . .

Can I just copy the more recent basic theme files to my ./sites/all/themes/[my_dev_site] folder and call it good?

austintnacious’s picture

So I downloaded basic 2.8.

Copied over basic.info, template.php and theme-settings.php to my ./sites/all/themes/[customized-basic] folder and although, I've flushed caches, saved theme settings pages, ran cron, update.php etc.

My theme still works BUT I still get now unique body classes and no access to the Zen theme settings.

I'm not a programmer but I do get what's supposed to be happening in the code from template.php below. . .

if (!$vars['is_front']) {
    // Add unique classes for each page and website section
    $path = drupal_get_path_alias($_GET['q']);
    list($section, ) = explode('/', $path, 2);
    $body_classes[] = basic_id_safe('page-'. $path);
    $body_classes[] = basic_id_safe('section-'. $section);

. . . it's just not doing what it's supposed to do!

I don't get body.page-$path or body.section-$section classes.

I used to in an earlier version of basic (2.1 maybe).

BTW, this is with D6.13.

Help?

Anonymous’s picture

Like other issue, I retested Basic 2.8 on a fresh d6.13 install and I have body classes, access to theme settings, everything works fine.

Make sure you named the functions correctly (not renamed your theme "mytheme" and leave functions as "basic_...", that you have template.php / theme-settings.php and that the body tag in page.tpl.php is like follow

<body class="<?php print $body_classes; ?>">

austintnacious’s picture

Status: Active » Closed (fixed)

THANKS!

That was it! Sorry for being so clueless. . . but I am!

I'd changed the theme to 'my_theme' but had not renamed the functions in template.php and page.tpl.php!!!

All's good now!
Thanks again.

Glad to have those node specific body classes back!!!

BTW, my copy of page.tpl had

<body class="<?php echo $body_classes; ?>">

I may have asked this a while back but is there any diff between echo and print?

Anonymous’s picture

haaa I think this is a question that you should ask to a high end PHP developper... not me, that is much more a designer/themer. When I asked this question to my fellow co-workers, the only thing I could undestand is that "print" is more complicated than "echo", and thus require more memory... but really, don't take this as a real answer, am not the right person to ask :)

Glad you fixed your problem !

perke’s picture

related to above:
I'm trying to get body classes specific to user role so I can style profile pages different per role. My users can have only one role. I've tried Themer module but that only gave me class for role of currently logged in user. Also tried messing with Pathauto and CustomToken, that also didn't helped.
I would appreciate any kind of help.

(using latest stable Basic + Drupal)

perke’s picture

Status: Closed (fixed) » Active
Anonymous’s picture

Not sure I understand (well.. I just woke up so maybe it's me...). You say : "to get body classes specific to user role" but then you say "that only gave me class for role of currently logged in user".

I thought that's what you wanted isn't it ?

perke’s picture

Nope, sorry if I wasn't clear.. I need to style profile pages per role, so if the user is in the Musician role his profile page is, lets say, with guitar in header. So I just need a body class="musician" when you're on that profile page. So it is basically same as you're on the "news" content type page and you get body class="node-type-news". Does that make any sense now?

I understand it might be issue if user is member of more than one role, but in my case they only can have one.

I actually made it with Custom Token and PathAuto but was able to get only "Authenticated" role as body class, but that's not what I can use :)

Thanks!

Anonymous’s picture

Try this, add it within the basic_preprocess_page function in the template.php

  // Adding body class on user profile
  if (arg(0) == 'user') {
    // loading user account data
    $user_account = user_load(array('uid' => arg(1)));
    // creating a string of roles
    $roles = implode(' ',$user_account->roles);
    // adding the string as body class
    $body_classes[] = $roles;
  }

This should give you more body classes with the role of the viewed user profile.

perke’s picture

Status: Active » Fixed

That did it! Awesome, many thanks!

This could, maybe, go into documentation or inside the theme somewhere if you find it appropriate.

Cheers!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.