Conditional Shortcode image display

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 🙂

Read More
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"]

Related posts

Leave a Reply

1 comment

  1. 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:

        // 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" />';
        } else {
            // Add default case
            $subject = "Default here";
            $subjectImg = '<img src="'.get_bloginfo('template_url').'/img/postInfoBox/default.png" alt="מדריך RSS" />';
        }
    

    That way, there will always be an image even if they give you bad data.