Need help with PHP: Show an image field when video field is empty I have been working with Drupal for some months now but I have not coded anything in it so I need help.

Situation: On my homepage there are 3 rows that contain blog teasers. On the first row the first video (youtube/vimeo) and the first image of the blog is shown. They are all styled responsively and it works fine. I use a view to do this.

What needs to change: When there is a video in the blog, I want to exclude the image.
So Video = No image, No video = Image, No video and No image = just the teaser text (which is always present).

What I have tried: Tried the Views Conditional module. Doesn't work since the replacement variable (example [photo]) does not contain the image itself.

Tried Views If Empty module. The logic works but messes up my CSS in a lot of ways and impossible to make it look like it should.

Solution?: I think that what I need is a PHP part in my View.
I have no experience at all with making this. What I have tried is visible below.
(messes up the homepage).

if (empty($fields[$row-&gt;field_alg_video_1]-&gt;last_render)) {
          $this-&gt;last_render = $fields[$row-&gt;field_alb_fotos]-&gt;last_render;
        }
        else {
          $this-&gt;last_render = '';
        }


I just threw some stuff together from the net. Can anyone help me out? :)
Trust on Views empty field settings :-)

Hide the image and the test field. Configure the video field empty setting telling that should show the image field: use the right token, something like this:

[field_image]


Then configure the image field empty setting with the text field.

So, if there's no vídeo Views will try to show the image field. When rednering the image field Vies will show the image if it's present, or the text field if image is also empty.