Got a problem with a shortcode.. i probebly dont know where & how to set the condition so it will display the right image according to the topic / category of the toturial..
Help Plz 🙂
function postInfoBoxSc( $atts ) {
extract( shortcode_atts( array(
'subject' => 'Category type',
'difficulty' => 'User Types',
'completiontime' => 'completion Time'
), $atts ) );
// Set image acorring to guide type
if ($subject == 'wordpress') {
$subjectImg = '<img src="'.get_bloginfo('template_url').'/img/postInfoBox/wordpress.png" alt="××ר×× ××ר×פרס" />';
} elseif ($subject == 'web design') {
$subjectImg = '<img src="'.get_bloginfo('template_url').'/img/postInfoBox/webDesign.png" alt="××ר×× ×× ××ת ×תר××" />';
} elseif ($subject == 'facebook') {
$subjectImg = '<img src="'.get_bloginfo('template_url').'/img/postInfoBox/facebook.png" alt="××ר×× ×¤××ס××ק" />';
} elseif ($subject == 'RSS') {
$subjectImg = '<img src="'.get_bloginfo('template_url').'/img/postInfoBox/rss.png" alt="××ר×× RSS" />';
}
return '
<br class="clear" />
<div class="postInfoBox">
'. $subjectImg .'
<h5>Guide information:</h5>
<ul>
<li><strong>Category:</strong> '. $subject .'</li>
<li><strong>User Lever:</strong> '. $difficulty .'</li>
<li><strong>completion Time:</strong> '. $completiontime .'</li>
</ul>
</div>
';
}
add_shortcode( 'postInfoBox', 'postInfoBoxSc' );
The Problem
For some reason the value of $subject doesent get updated like the othere values and isnt being passed trough the shortcode and the image isn’t changing because of that
What Am I Doing Wrong ??
(just added per request)
this is the shortcode i am entreing in wordpress editor when writing a post:
[postInfoBox subject="somthing" difficulty="hard" completiontime="2-5 minuts"]
I wasn’t able to replicate your problem exactly, but here’s a tip: include some default behavior, in case the user puts in a bad value for the subject:
That way, there will always be an image even if they give you bad data.