if-condition custom fields
-
Hi,
i can’t really cope with php, that’s why i am looking for help regarding the following scenario:
i would like to display the content of 2 custom fields inside a div, but only if there is any content to display. otherwise the div should not appear.my question sounds similiar to this one but i wasn’t able to solve my problem with the code snippets there.
so far i used the following improvisational code on top of my sidebar:
<?php if($key="Bonusbild-Class") { ?><br /> <div class="<?php $key="Bonusbild-Class"; echo get_post_meta($post->ID, $key, true); ?>" align="center"> <img src="<?php $key="Bonusbild"; echo get_post_meta($post->ID, $key, true); ?>"><br /> <small4><?php $key="Bildunterschrift"; echo get_post_meta($post->ID, $key, true); ?></small4><br /></div><br /><br /> <?php } ?>
i have 3 conditional fields:
“Bonusbild-Class” is for the surrounding div, but that one is actually always the same. it only has been important to me because i tried to build an if-condition with it at the beginning of the code.
“Bonusbild” would be the picture and “Bildunterschrift” the text.this code works well if there is content in “Bonusbild” and / or “Bildunterschrift”. but if no custom fields are filled with information the following part of the sidebar starts beneath a big gab where the div-box would normally be. it seems that the “br”-tags are still working and that my attempt for an “if-condition” didn’t work entirely.
does someone know how i could rewrite the code to let the sidebar begin on top even if there are no conditional fields to display ?
i would be very glad for an answer.
sorry for my english.bs.
- The topic ‘if-condition custom fields’ is closed to new replies.