Hi,

I have set the default class to "link" but need it to be "front" for the front page. I have tried to do the following in node.tpl.php, under teaser view mode :

if ($is_front):

		   $node->field_page_link['und'][0]['attributes']['class'] = "front";
		   print render($content['field_page_link']);

endif;

but the link fields is still displayed with the default class.

Any idea how I could do this?

Comments

Anonymous’s picture

The problem is with the markup:

[0] => Array
        (
            [#markup] => <a href="/node/1" class="link">Link1</a>
        )

    [1] => Array
        (
            [#markup] => <a href="/node/2" class="link">Link2</a>
        )

    [2] => Array
        (
            [#markup] => <a href="/node/3" class="link">Link3</a>
        )

How can I change the class name so that render() prints out the correct class name?

Anonymous’s picture

Ok, I managed to do this in template.php

function my_theme_preprocess_page(&$vars) {

  $node = $vars['node'];
  
   if($vars['is_front']) {
  
  	   $node->field_page_link['und'][0]['attributes']['class'] = "front";
  }
  
    }
jkingsnorth’s picture

Title: custom class name for front page » Custom class for link to front page
Issue summary: View changes
Status: Active » Fixed

Status: Fixed » Closed (fixed)

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