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.

I have a checked a few links but nothing seems to for me in getting the attribute value of a shortcode so that I can use it in a condition.

function bf_shortcode_slideshow($atts) {
  extract(shortcode_atts(array(
    'location' => ''
  ), $atts));

  ob_start();
  if  ( $location = 'home' ) {
  classslider = 'homeslider';
}
  include(dirname(dirname(__FILE__)) . '/templates/slideshow.php');
  return ob_get_clean();
}
add_shortcode('rotator', 'bf_shortcode_slideshow');

In the slideshow.php I have a

echo 'classslider=' . $classslider;

My result for $classslider is blank ( nothing is displayed ) Is there another way you should compare $location to a string value set ?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

include changes the scope. You would need to declare $classslider global before defining it, and then use global $classslider; before using it.

function bf_shortcode_slideshow($atts) {
  global $classslider;
  extract(shortcode_atts(array( ...

I think that will fix your problem.

I don't understand why you are using include at all though. There must be a better way to make that slideshow work.

share|improve this answer
    
Thank you for your response. When I add global $classslider and then echo out $classslider in the included file, I still don't get anything returned. I believe the included file seperate from the shortcode creation is to keep the code clean. –  thembisue Jan 24 '13 at 20:46
    
Did you add global $classslider; to the included file as well? –  s_ha_dum Jan 24 '13 at 20:47
    
yes I added it global $classslider; at the start of the included file –  thembisue Jan 24 '13 at 20:49
    
Ok In addition so your solution,I made a change in how the condition was written and now it is working. the condition shouuld have been if ($location = 'home') {$classslider = "homeslider";} Thank you –  thembisue Jan 24 '13 at 20:54
    
Explaining exactly what you did might help the next person who wanders by. –  s_ha_dum Jan 24 '13 at 20:55
show 1 more 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.