Support » Plugin: Multiple content blocks » [Plugin: Multiple content blocks] Hide wrap div if the block doesn't have content

  • Resolved weremoose

    (@weremoose)


    Hello,

    I am trying out the plugin and it seems to wor fine so far. I just have a question about implementing it in my template.

    I am using the plugin to split my content in different divisions if the content is too long. So I use the code given to activate the plugin in my template and I put it within my div. The thing is that I wouldn’t like my div to show up if I don’t have content in “my_block”.

    Right now I have something like this:

    <div class="block_div">
       	<?php the_block('blockname'); ?>
     </div>

    I googled a bit and there is a way to do the thing I want with “the_content” but I would like to apply the same thing in “the_block”.

    Here is the code I found:

    <?php if($post->post_content=="") : ?>
    
    <!-- Do stuff with empty posts (or leave blank to skip empty posts) -->
    
    <?php else : ?>
    
    <!-- Do stuff to posts with content -->
    
    <?php endif; ?>

    Any idea on how to do that? It should be fairly easy, I am just not that familiar with php yet but hopefully I will get there.

    Any help is much appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter weremoose

    (@weremoose)

    Ok, I figured this out using
    <?php $content_to_edit = get_the_block('blockname'); ?>

    So I used it like this in my code and it worked perfectly:

    <!-- Multiblock Code -->
    <?php $my_block = get_the_block('my_block'); ?>
    <?php if ($my_block == "") : ?>
    <?php else : ?>
       <div class="my_div">
         <?php echo $my_block; ?>
       </div>
    <?php endif ?>

    @weremoose

    Thanks for posting your solution. This is exactly what I need.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Multiple content blocks] Hide wrap div if the block doesn't have content’ is closed to new replies.