vektor
vektor

Reputation: 45

Div without content hide

I have two custom types inside a div. I need hide main div if custom type is empty.

This is my code: (I want to hide div "one" if "titulo_caja_superior" custom type is empty.)

<div class="contenidos">
    <div class="left">
        <div class="one" style="background-color:<?php echo esc_url( of_get_option( 'primary_color' ) ); ?>;color:#FFFFFF;"><div><div class="titulo"><?php the_field('titulo_caja_superior'); ?></div><div class="contenido"><?php the_field('cajaizquno'); ?></div></div>
        <div class="two" style="background-color:<?php echo esc_url( of_get_option( 'header_color' ) ); ?>;color:<?php echo esc_url( of_get_option( 'secundary_color' ) ); ?>;"><div class="titulo"><?php the_field('titulo_caja_inferior'); ?></div><div class="contenido"><?php the_field('cajaizqdos'); ?>></div></div>
    </div>
</div>

Upvotes: 0

Views: 79

Answers (1)

Fabricator
Fabricator

Reputation: 12772

Add an if statement

<div class="contenidos">
    <div class="left">
        <?php if(!empty(the_field('titulo_caja_superior'))): ?>
            <div class="one" style="background-color:<?php echo esc_url( of_get_option( 'primary_color' ) ); ?>;color:#FFFFFF;"><div><div class="titulo"><?php the_field('titulo_caja_superior'); ?></div><div class="contenido"><?php the_field('cajaizquno'); ?></div></div>
        <?php endif; ?>

        <div class="two" style="background-color:<?php echo esc_url( of_get_option( 'header_color' ) ); ?>;color:<?php echo esc_url( of_get_option( 'secundary_color' ) ); ?>;"><div class="titulo"><?php the_field('titulo_caja_inferior'); ?></div><div class="contenido"><?php the_field('cajaizqdos'); ?>></div></div>
    </div>
</div>

Upvotes: 2

Related Questions