First, you have a syntax error. Your server might not have been configured to allow short tags.
Try using <?php echo
instead of <?=
Second, you could either use the Field formatter conditions module to add display conditions to your fields or create a custom code field in Display Suite.
EDIT: How to add a Display Suite custom code field in your own module:
1- Create a new module and add this code in it (remember to change MY_MODULE with the desired name):
/**
* Implements hook_ds_fields_info().
*
* We add the code fields to Display Suite here.
* Then we specify a callback function that will handle the display logic.
*/
function MY_MODULE_ds_fields_info($entity_type) {
$fields = array();
// Add a new custom code field. It should be available in Display Suite.
$fields['node']['tags_custom'] = array(
'title' => t('Tags (custom)'),
'field_type' => DS_FIELD_TYPE_FUNCTION,
'function' => 'MY_MODULE_ds_field_tags_custom',
);
if (isset($fields[$entity_type])) {
return array($entity_type => $fields[$entity_type]);
}
}
/**
* Callback to show the tags field only if it has a value.
*/
function MY_MODULE_ds_field_tags_custom($field) {
$node = $field['entity'];
// Get the tags field value.
$tags = isset($node->content['tags'][0]['value']) ? $node->content['tags'][0]['value'] : NULL;
// Return a string or nothing, depending on the tags field value.
if (!empty($tags)) {
return t('Category: ') . $node->content['tags'][0]['value'];
}
else {
return NULL;
}
}
2- Now, if you go to admin/structure/ds and click on the Manage display link, you will see your new field Tags (custom). Set its label to hidden and publish it in the desired area.
<?php echo
instead of<?=