GetSimple Support Forum
conditional tag - show custom field only if has value? - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: General Questions and Problems (http://get-simple.info/forums/forumdisplay.php?fid=16)
+--- Thread: conditional tag - show custom field only if has value? (/showthread.php?tid=3920)



conditional tag - show custom field only if has value? - ad2003 - 2012-11-23

Hi there!

Has anybody an idea how to get content only be shown as custom field has value?

e.g: I am using GS Blog Custom Fields, I have a custom field calles "pic1"

I want to have some images within a class like:

<img class="thumbnail" src="<?php echo $post->pic1; ?>" width="100" height="80" alt="" title="" />

But if theres no custom field value I don't want to have the class and stuff to be loaded.

I tried something like this:

<?php if ($post->pic1, TRUE) { ?> <img class="thumbnail" src="<?php echo $post->pic1; ?>" width="100" height="80" alt="" title="" /> <?php } ?>

But this doesn't work...any suggestions?

Thank you!

AD


RE: conditional tag - show custom field only if has value? - shawn_a - 2012-11-24

true is only to evaluate booleans.

You need to use isset() or !isempty() dependnig on what you are checking for.


RE: conditional tag - show custom field only if has value? - ad2003 - 2012-11-24

(2012-11-24, 00:19:03)shawn_a Wrote: true is only to evaluate booleans.

You need to use isset() or !isempty() dependnig on what you are checking for.

Hi Shawn -

thank you for the reply. Could you be so kind and have a look at this example:
__________________________________________
<?php if(isset($_GET['post']) && $blogSettings["customfieldname"] == 'Y') { ?> do stuff <?php } ?>
__________________________________________

How should I write it than?
Thank you!

AD


okoko: Thanks - it works like this:

<?php if (!empty($post->customfieldname)) { ?>
do stuff <?php } ?>