views:

22

answers:

2

So I am obviously not a very good programmer. I have written this small function:

function dispAdjuggler($atts) {
extract(shortcode_atts(array(
    'slot' => ''
), $atts)); 

$adspot = '';
$adtype = '';

// Get blog # we're on
global $blog_id;
switch ($blog_id) {
    case 1:
        // root blog HOME page
        if (is_home()) {
            switch ($slot) {
                case 'top_leaderboard':
                    $adspot = '855525';
                    $adtype = '608934';
                break;
                case 'right_halfpage':
                    $adspot = '855216';
                    $adtype = '855220';
                break;
                case 'right_med-rectangle':
                    $adspot = '858222';
                    $adtype = '613526';
                break;
                default:
                    throw new Exception("Ad slot is not defined");
                break;
            }

When I reference the function on a page like so:

<?php dispAdjuggler("top_leaderboard"); ?>

The switch is throwing the default exception. What am I doing wrong here?

Thanks!!

+2  A: 

Without know what the shortcode_atts() function does, it looks like you're passing in array to set default values ('slot' = empty string), which extract() then converts into $short = ''

extract(shortcode_atts(array(
    'slot' => ''
), $atts)); 

right? Now that $slot is the empty string, it won't match any of the cases in your switch, and therefore the default case gets triggered, which throws the "Ad slot is not defined" exception.

Marc B
me => duhThanks! :)
Marty
A: 

Aren't you missing the extract type parameter?

http://us.php.net/manual/en/function.extract.php

try:extract(shortcode_atts(array( 'slot' => ''),EXTR_OVERWRITE , $atts));or just add an additional ","