Khazd0rf
Khazd0rf

Reputation: 1

Hide Div title if there's no content

I'm very newbie regarding PHP, I'm trying to configure my wordpress Loop.

I figured out how to display my customfield in my template, I manually added a title before my taxonomy and custom fields, but I'd like it doesn't show if the taxonomy is empty.

Here is the code:

 <div class="customfields"> 
      <h2 class="widgettitle">My Title</h2>
      <?php echo do_shortcode('[tax id="agences" before="Agences : " separator=", " after=""]'); ?> 
      <?php echo do_shortcode('[custom_fields_block]'); ?>
 </div>

I would very much appreciate your help!

Thanks a ton, T.

Upvotes: 0

Views: 987

Answers (2)

AdamskiFTW
AdamskiFTW

Reputation: 109

If you want to show content in HTML only if certain variables contain a value then you can create a simple if statement that uses PHP's isset function to determine whether or not the variables are set, and if true place some HTML on the page. You can read more about isset here.

Upvotes: 0

user2768948
user2768948

Reputation:

So code should be
<?php $taxonomy = do_shortcode('[tax id="agences" before="Agences : " separator=", " after=""]'); ?>

<div class="customfields">
    <?php if(!empty($taxonomy)) : ?>
        <h2 class="widgettitle">My Title</h2>
        <?php echo $taxonomy; ?> 
    <?php endif; ?>
    <?php echo do_shortcode('[custom_fields_block]'); ?>
</div>

Upvotes: 1

Related Questions