Multiple content blocks
[resolved] Hide wrap div if the block doesn't have content (3 posts)

  1. weremoose
    Posted 5 years ago #


    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'); ?>

    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!

  2. weremoose
    Posted 5 years ago #

    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; ?>
    <?php endif ?>
  3. katart17
    Posted 5 years ago #


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

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Multiple content blocks
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic