On a site I'm developing the first blog teaser on the blog index page /blog is displayed bigger than the other teasers. I do this with a class 'featured', can I add a function in template.php to add this class to the first blog teaser on the /blog page?

Thanks for your time

  • Is the /blog page an actual page or is it just an archive/listing of posts on that url?
    – hampusn
    Sep 16 '12 at 9:09

In the template_preprocess_node hook you can use $vars['id'] to get the array index in the order that the nodes are printed.

You'll need to replace COND_FOR_BLOG with whatever logic you have for checking that.

Example to get you started:

function THEME_OR_MODULE_preprocess_node(&$vars) {
  if (COND_FOR_BLOG && $vars['id'] == 1) {
    $vars['classes_array'][] = 'featured';

Edit: Note that $vars['id'] is not zero-based so $vars['id'] == 1 actually gives the first post.


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.