1

I want it so that in my page.tpl.php file if the user has selected "Standard" as the "Page Type" term reference it prints an extra bit of html.

I tried something along the lines of the code below but have not had any luck so any help would be greatly appreciated.

<?php $page_type = field_get_items('node', $node, 'field_page_type');
if ($page_type == 'Standard') {
    print "worked";
} ?>

If I print the "field_page_type" value further down the page it prints "Standard" on the page but if I use the if statement above it doesn't print the "worked" result.

I am using Drupal 7.

1 Answer 1

1

The above use of field_get_items('node', $node, 'field_page_type'); is going to return an array that looks like:

Array
(
    [0] => Array
        (
            [tid] => 549
        )

)

But what you want is the value of the term so you'll need to do the following:

<?php $page_type = field_view_field('node', $node, 'field_search_type');
if ($page_type['#items'][0]['taxonomy_term']->name == 'Standard') {
    print "worked";
} ?>
2
  • That is absolutely perfect thank you. I changed "field_search_type" in your response to "field_page_type" and it worked as I wanted. Thank you so much! May 25, 2016 at 13:40
  • Great and yes, apologies for leaving that. It was from testing on my end. Glad it worked for you!
    – stiknoltz
    May 25, 2016 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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