Such a situation, when you add a picture to a post, then a picture and a brief description is displayed, if the picture is not added, a stub is displayed instead.
In php I removed the output of the stub and now I want to make sure that when the picture is not added, the description stretches the entire width.
Here is the code:

 if ( ! isset( $barcelona_placeholder_img ) || false === $barcelona_placeholder_img ) { $barcelona_placeholder_img = 'assets/images/placeholders/' . ( $size == 'full' ? 'barcelona-full' : $size ) . '-pthumb.jpg'; if ( is_readable( BARCELONA_SERVER_PATH . $barcelona_placeholder_img ) ) { @list( $barcelona_width, $barcelona_height ) = getimagesize( BARCELONA_SERVER_PATH . $barcelona_placeholder_img ); } $barcelona_placeholder_img = BARCELONA_THEME_PATH . $barcelona_placeholder_img; } 

I know that I need to connect to this js that if there is no picture, he would draw a different style or assign another class, but I don’t know how to do it

Please tell me.

  • You can do this at php. if there is no picture in the view where you display the text of the block, give one more class - Boris Runs
  • The problem is that I don’t know where to insert it, I found the code that outputs it and removed the line that prints it out, and now I don’t know what and where to enter other styles - Eugene

1 answer 1

You need to write code like this, you can do without JS

<a class="<?= $image ? 'first_class' : 'second_class' ?>"></a>

This code is equivalent to:

<a class="<?php if ($image) { echo 'first_class'; } else { echo 'second_class'; } ?>"></a>

You need to register the correct if conditions and html markup.