/    Sign up×
Community /Pin to ProfileBookmark

Help with hiding DIV containing variable outputs if empty.

OK, so I tried the JavaScript route and despite lots of excellent help, I couldn’t achieve what I needed.

Basically, I’m running a WordPress site, hosted locally. It is to be used as a database containing details about sites we serve – things like IP Address, OS, Ram etc.

Im using a plugin called “advanced custom fields” which is where the information goes into. The fields can be displayed on the page by manually inserting <?php the_field(‘field_name’); ?> into the template.

Now each of these fields that I have put into the single.php (template for a single post) are wrapped in <divs> purely so I can add some style to them to look more presentable on the site.

The one and only problem I am facing is that, as there are 40+ of these <divs> containing the php field embed codes, some of them will not be filled in. Now I want to be able to hide these <divs> if they are empty just to avoid headaches trying to scroll past 20 blank boxes looking for info on the post, but its proving quite difficult for me as I am quite new to coding.

Here is the code from a forum on the plugins site, which in theory hides the “Price: ” if it is empty.

[CODE]<?php if (get_field(‘price’) != “”) { ?>
Price: <?php the_field (‘price’); } ?>[/CODE]

Now here is how mine is displayed (just a small excerpt):

[CODE]
<div class=”post3″ >
<strong>Host Control Software Details</strong><br />
<div class=”inside”><?php the_field(‘host_control’); ?></div>
</div>

<div class=”post3″ >
<strong>Respak Software Details</strong><br />
<div class=”inside”><?php the_field(‘respak_details’); ?></div>
</div>

<div class=”post3″ >
<strong>QSR Software Details</strong><br />
<div class=”inside”><?php the_field(‘hostess_details’); ?></div>
</div>

[/CODE]

How do I use “<?php if (get_field(‘field name’) != “”) { ?>” with my coding above with regards to hiding the entire “post3” DIV fir the specific field output?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 19.2011 — [code=php]
<?php if (get_field('host_control') != "") { ?>
<div class="post3" >
<strong>Host Control Software Details</strong><br />
<div class="inside"><?php the_field('host_control'); ?></div>
</div>
<?php } ?>
[/code]
Copy linkTweet thisAlerts:
@stylishjmauthorAug 22.2011 — Excellent, that worked perfectly thanks!
×

Success!

Help @stylishjm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...