1

I have a node--content_type.tpl.php template where I want to print the taxonomy term associated with the current content as plain text so that I can surround it with a div class to print a special label for content with the selected term.

So for example I have chosen "Sold" as a taxonomy term and want to display the word with no link to the taxonomy terms page. It currently outputs as "<a datatype="" property="rdfs:label skos:prefLabel" typeof="skos:Concept" href="/taxonomy/term/6">Sold", so links to the taxonomy terms page.

I am currently using this code to print the term:

<?php

if(!empty($node->field_p_status['und'][0]['value'])) {
  $status = $node->field_p_status['und'][0]['value'];
}

?>

<?php if(isset($status)) { ?>

<?php print render(field_view_field('node', $node, 'field_p_status', array('label'=>'hidden'))); ?>

<?php } ?>

Any idea how to strip it down so it prints just "Sold"?

1

2 Answers 2

1

To print the raw value you can use this code:

<?php

if(!empty($node->field_p_status['und'][0]['value'])) {
  print $node->field_p_status['und'][0]['value'];
}
?>
1
  • It didn't seem to print for some reason. Please see my answer below... (Thank you by the way). Jul 29, 2016 at 7:51
1

I used a different solution which was better for me by printing the id of the taxonomy term (which I then wrapped in a div class). Obviously that didn't technically print the taxonomy term itself, but allowed me to have a class where I could style a background image unique to that class to show to the user (a Sold banner).

The code I used was:

                    <?php

                        if(!empty($node->field_p_status['und'][0]['value'])) {
                            $status = $node->field_p_status['und'][0]['value'];
                        }

                    ?>

                    <?php if(isset($status)) { ?>

                        <div class="status_<?php print $node->field_p_status[$node->language][0]['tid'] ?>"></div>

                    <?php } ?>
1

Your Answer

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

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