1

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"]
8
  • What's your current outcome and expected outcome? Oct 22, 2011 at 21:56
  • currently i am getting the 'wordpress' as the value of $subject.. i want the value to change when entereing the shortcode like this: [postInfoBox subject="somthing" difficulty="hard" completiontime = "2-5 minuts"] ... see any reason why it doesent do that ?
    – Sagive
    Oct 23, 2011 at 0:33
  • also i would like the image to change according to the entered value of $subject (see the if condition)..
    – Sagive
    Oct 23, 2011 at 0:35
  • 2
    Unless you paste here the actual text you are testing on and output... I can't help. Your code seems OK, but with no test text... I can't tell. Oct 23, 2011 at 1:19
  • Agreed with @EarnestoDev: we need to see the actual shortcode text being used. Oct 23, 2011 at 2:43

1 Answer 1

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.

1
  • Awesome, glad I could help!
    – Andy Adams
    Oct 27, 2011 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.