Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$20
Making values in meta box conditional?
But what I want to achieve is to make each text field in the meta box, so if no image url is added it won't show in the slider as an image, or broken image as the url is not there.
So how do I make the values in the meta box conditional? Here's the code I suspect needs to tweaking:
<div id="slider" class="nivoSlider">
<img src="<?php $my_meta = get_post_meta($post->ID,'_my_meta',TRUE); echo $my_meta['urltwo']; ?>" alt="" />
<img src="<?php $my_meta = get_post_meta($post->ID,'_my_meta',TRUE); echo $my_meta['urlthree']; ?>" alt="" />
<img src="<?php $my_meta = get_post_meta($post->ID,'_my_meta',TRUE); echo $my_meta['urlfour']; ?>" alt="" />
<img src="<?php $my_meta = get_post_meta($post->ID,'_my_meta',TRUE); echo $my_meta['urlfive']; ?>" alt="" />
</div>
This question has been answered.
LeTune | 08/22/11 at 4:22am
Edit
(5) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
08/22/11
4:32amUtkarsh Kukreti says:
<div id="slider" class="nivoSlider">
<?php
$my_meta = get_post_meta($post->ID,'_my_meta',TRUE);
foreach(array('urltwo', 'urlthree', 'urlfour', 'urlfive') as $key) {
if(isset($my_meta[$key])) {
echo "<img src='" . $my_meta[$key] . "'/>";
}
}
?>
</div>
Previous versions of this answer: 08/22/11 at 4:28am | 08/22/11 at 4:28am | 08/22/11 at 4:32am
-

Last edited:
08/22/11
4:28amAdamGold says:
<?php $my_meta = get_post_meta($post->ID,'_my_meta',TRUE); ?>
<div id="slider" class="nivoSlider">
<?php if( isset($my_meta['urltwo']) && $my_meta['urltwo'] != '' ) { ?>
<img src="<?php echo $my_meta['urltwo']; ?>" alt="" />
<?php } ?>
<?php if( isset($my_meta['urlthree']) && $my_meta['urlthree'] != '' ) { ?>
<img src="<?php echo $my_meta['urlthree']; ?>" alt="" />
<?php } ?>
<?php if( isset($my_meta['urlfour']) && $my_meta['urlfour'] != '' ) { ?>
<img src="<?php echo $my_meta['urlfour']; ?>" alt="" />
<?php } ?>
<?php if( isset($my_meta['urlfive']) && $my_meta['urlfive'] != '' ) { ?>
<img src="<?php echo $my_meta['urlfive']; ?>" alt="" />
<?php } ?>
</div>
What I am doing here is making sure the value even exists before making an image with it.- 08/22/11 4:47am
LeTune says:thanks Adam, that did the trick. Let me know if you are interested in working for us at MonsterThemes.com as dedicated wp developer.
- 08/22/11 4:47am
-

Last edited:
08/22/11
4:31amIvaylo Draganov says:Hello,
simply change the queries to your meta values to include an 'if' statement before them:
<?php if ( get_post_meta( $post->ID,'_my_meta', TRUE ) && $my_meta['urltwo'] != '' ) {
$my_meta = get_post_meta($post->ID,'_my_meta',TRUE);
?>
<img src="<?php echo $my_meta['urltwo']; ?>" alt="" />
<?php } ?>
* also keep the variable out of the img src attribute
Reformat all your img tags like this and let me know how it went. Cheers!Previous versions of this answer: 08/22/11 at 4:31am
-

Last edited:
08/22/11
4:31amJohn Cotton says:How about this?
<div id="slider" class="nivoSlider">
<?php
$meta = get_post_meta($post->ID,'_my_meta',TRUE);
if ( $meta) {
$fields = array ( 'urltwo', 'urlthree', 'urlfour', 'urlfive' );
foreach( $fields as $field ) {
if( !empty( $meta[$field] ) ) {
echo '<img src="'.$meta[$field].'" alt="" />';
}
}
}
?>
</div>
-

Last edited:
08/22/11
4:35amNenad Ticaric says:<?php
if(get_post_meta($post->ID,'_my_meta',TRUE)){
$my_meta = get_post_meta($post->ID,'_my_meta',TRUE);
foreach($my_meta as $meta){
?>
<img src="<?php echo $meta; ?>" />
<?php
}
}
?>Previous versions of this answer: 08/22/11 at 4:35am
This question has expired.
AdamGold had additional discourse to offer.
LeTune voted on this question.
Current status of this question: Completed
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
