Sign Up for OSTraining

Welcome, Guest
Username: Password: Remember me

TOPIC: What is the PHP snippet for a custom CSS class on a block?

What is the PHP snippet for a custom CSS class on a block? 1 year 2 weeks ago #45435

  • eligeski
  • eligeski's Avatar
  • OFFLINE
  • OSTudent
  • Posts: 39
  • Karma: 0
Hi there,

I need to add a CSS class to a block. I know I need to add something along the lines of <?php print $block_classes; ?> to my theme's block.tpl.php file to make the classes appear.

Is it literally $block_classes that needs to be added or is it $block_<name of custom class>? Or something else? Nothing I have tried has worked.

Thanks,

Erica
Please become a member of OSTraining to reply to this post.

What is the PHP snippet for a custom CSS class on a block? 1 year 2 weeks ago #45439

  • tessa
  • tessa's Avatar
  • OFFLINE
  • Moderator
  • Posts: 3950
  • Thank you received: 134
  • Karma: 9
Hi Eligeski,

It depends where that variable is coming from, so the answer could vary depending on what CMS you are using.

Since you mentioned "theme" I am assuming you are speaking of WordPress? :-)
Warm Regards,

Tessa Mero



Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

What is the PHP snippet for a custom CSS class on a block? 1 year 2 weeks ago #45440

  • tessa
  • tessa's Avatar
  • OFFLINE
  • Moderator
  • Posts: 3950
  • Thank you received: 134
  • Karma: 9
Assuming you are using WordPress, (I know I'm getting too excited), you would use this code to use CSS block classes:
<?php echo "<$block class='your-class-name'>"; ?>

Where $block would probably be whatever it's defined to be, whether it's h1, td, or whatever.

If you put an underscore between the variable and the word class, how would you get the class name? :-)

Let me know if this works.
Warm Regards,

Tessa Mero



Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

What is the PHP snippet for a custom CSS class on a block? 1 year 2 weeks ago #45443

  • tessa
  • tessa's Avatar
  • OFFLINE
  • Moderator
  • Posts: 3950
  • Thank you received: 134
  • Karma: 9
One more thing, because $block is a variable for a tag, you should use </$block> to close the tag as well. :-)
Warm Regards,

Tessa Mero



Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

What is the PHP snippet for a custom CSS class on a block? 1 year 2 weeks ago #45454

  • eligeski
  • eligeski's Avatar
  • OFFLINE
  • OSTudent
  • Posts: 39
  • Karma: 0
Sorry I should have included that. I'm running Drupal 7.
Please become a member of OSTraining to reply to this post.

What is the PHP snippet for a custom CSS class on a block? 1 year 2 weeks ago #45458

  • tessa
  • tessa's Avatar
  • OFFLINE
  • Moderator
  • Posts: 3950
  • Thank you received: 134
  • Karma: 9
Thanks Eligeski for providing that information.

For Drupal, the block classes are defined with:
<?php print block_class($block); ?> 
Warm Regards,

Tessa Mero



Follow us on Twitter - twitter.com/OSTraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

Sign Up for OSTraining

Powered by Kunena Forum

Open Source Training is not affiliated with or endorsed by the Joomla, WordPress or Drupal projects.
All product names and trademarks are the property of their respective owners.

Copyright 2013 Open Source Training, LLC. All rights reserved.