I have a homepage view that consists of 3 fields:

  1. Title
  2. Body
  3. Image (field_image)

Both title and body field will always have data, but not for the image field. Therefore, for nodes which doesn't have image, the title and body (summary) will be displayed. For nodes which have image, only the title and image will be displayed. Can someone lend a help with the PHP code to be used? Thanks in advance!

Comments

johnv’s picture

Status: Active » Postponed (maintainer needs more info)

So, if Image exists, the Body is hidden?
Haven't tried this, but one of these approached could work:

- create a new field 'Global PHP';
- You may need to set Image field to 'exclude from display';
- set the PHP-code to: return ($data->field_image[0]['und']['value']) ? NULL : $data->field_body[0]['und']['value'];

or:
- create a new field 'Global PHP';
- You may need to rearrage this field to be before or after Image field;
- in the PHP-code, clear $data->field_body[0]['und']['value'] when isset(Image) = TRUE;

liam morland’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Fixed

If you need further help, please re-open and provide details.

Status: Fixed » Closed (fixed)

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