A
A
Alexander Ruzhevich2015-12-22 23:16:31
WordPress
Alexander Ruzhevich, 2015-12-22 23:16:31

Checking if a Wordpress post image exists?

Good day. Faced such a problem, when creating a record in the main field of WordPress, the main text is displayed, everything else is displayed in additional fields. But, now you need to throw an image next to the text, there seems to be no problem, but since everything on the bootstrap works naturally, the image and the text are not friendly, hence the question: how to make WordPress check the presence of an image in the post before displaying the post?
something like:

если картинка есть то
<div class="row">

<div class="col-sm-6">картинка</div>


<div class="col-sm-6">текст</div>

</div>

если картинки нет
<div class="row>


<div class="col-sm-12">текст</div>

</div>

also that it is preferable to check the presence of an image in an additional field
если что то есть в поле <?php echo do_shortcode('[types field="post_image"][/types]'); ?></div>

то

<div class="row">

<div class="col-sm-6">вставить содержимое поля</div>


<div class="col-sm-6">текст</div>

</div>

если поле пустое то
<div class="row>


<div class="col-sm-12">текст</div>

</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
megamutex, 2015-12-23
@megamutex

Add. Are the fields displayed by the plugin? For example, I use ACF. I checked for the presence of an image like this:

<?php
$images = get_field('img');
if( $images):
?>

<!-- Выводим то, что нужно, если картинка есть-->
                        <?php else: ?>
<!-- Выводим то, что нужно, если картинки нет-->
                        <?php endif; ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question