0

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 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Aren't you missing the extract type parameter?

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

1 Comment

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

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.