Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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"]
share|improve this question
    
What's your current outcome and expected outcome? –  EarnestoDev Oct 22 '11 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 SEO Oct 23 '11 at 0:33
    
also i would like the image to change according to the entered value of $subject (see the if condition).. –  Sagive SEO Oct 23 '11 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. –  EarnestoDev Oct 23 '11 at 1:19
    
Agreed with @EarnestoDev: we need to see the actual shortcode text being used. –  Chip Bennett Oct 23 '11 at 2:43
show 3 more comments

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
Thats great thinking man. thanks a lot :) –  Sagive SEO Oct 27 '11 at 19:32
    
Awesome, glad I could help! –  Andy Adams Oct 27 '11 at 20:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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