Support

Account

Home Forums Front-end Issues Hide containing div if fields are empty

Solved

Hide containing div if fields are empty

  • Hello.
    I’m having a div containing a h3-headline and a repeater that inputs values into li‘s:

    <div class="publications">
        <h3>Publications</h3>
        <ul>
            <?php if( have_rows('subpage_publications') ):
    	    while ( have_rows('subpage_publications') ) : the_row(); ?>
    
            <li>
                <a href="<?php the_sub_field('document'); ?>">
                    <?php the_sub_field('document_name'); ?>
                </a>
            </li>
    
            <?php endwhile; ?>
            <?php endif; ?>
    
        </ul>
    </div>

    Is there any way to hide the entire div if the fields are empty? Because if the fields are empty now, the headline still prints and I don’t want that.

    Thanks in advance

  • try it like this

    
    <?php if( have_rows('subpage_publications') ): ?>
    	    
    <div class="publications">
        <h3>Publications</h3>
        <ul>
            <?php while ( have_rows('subpage_publications') ) : the_row(); ?>
    
            <li>
                <a href="<?php the_sub_field('document'); ?>">
                    <?php the_sub_field('document_name'); ?>
                </a>
            </li>
    
            <?php endwhile; ?>
    
        </ul>
    </div>
    
    <?php endif; ?>
    
  • That did it! Thanks a lot

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Hide containing div if fields are empty’ is closed to new replies.