0

I'm trying to create a Shortcode to display scores between to teams. I've got this far, but I can't seem to get variables into the damn thing. I thought the arrays where used for that, but apparently it doesn't work like that.

 function get_gamecentre($atts, $content = null) {
    extract(shortcode_atts(array(
            "HOME-IMG" => '',
            "AWAY-IMG" => '',
            "HOME-NAME" => '',
            "AWAY-NAME" => '',
            "HOME-POINTS" => '',
            "AWAY-POINTS" => '',
    ), $atts));
    return '<div style="background-color: #360000;width: 670px; height: 250px; color: white; padding: 10px;">';
    return '<table style="color: white;" width="100%">';
    return '<tbody>';
    return '<tr>';
    return '<td style="text-align: center;" width="340"><img class="size-full wp-image-32 alignnone aligncenter" title="tribes-pp" src="'.$HOME-IMG.'" alt="" width="140" height="140" /></td>';
    return '<td width="34"></td>';
    return '<td width="350"><img class="alignnone size-full wp-image-32 aligncenter" src="'.$AWAY-IMG.'" alt="" width="140" height="140" /></a></td>';
    return '</tr>';
    return '<tr>';
    return '<td style="text-align: center;">[box color=red]'.$HOME-NAME.'[/box]</td>';
    return '<td style="text-align: center;">VS</td>';
    return '<td style="text-align: center;">[box color=red]'.$AWAY-NAME.'[/box]</td>';
    return '</tr>';
    return '<tr>';
    return '<td style="text-align: center;">[box color=green]'.$HOME-POINTS.'[/box]</td>';
    return '<td style="text-align: center;">VS</td>';
    return '<td style="text-align: center;">[box color=red]'.$AWAY-POINTS.'[/box]</td>';
    return '</tr>';
    return '</tbody>';
    return '</table>';
}
add_shortcode("gamecentre", "get_gamecentre");

1 Answer 1

3

Simply don't call return more than once.

Just add your output to a variable:

$some_variable_name = 'mention the = at the beginning of this line';
$some_variable_name .= 'Take a look at the .Period before the = in this line';
$some_variable_name .= 'then add more lines always with the period';
// at the end of your shortcode function:
// if you want to echo something:
echo $some_variable_name;
// or:
return print $some_variable_name;
// If you want to just return it in code:
return $some_variable_name;

Also #1: Keep your variable names with lowerspace characters.

Also #2: In php, variables always have to use _ underline instead of - dash.

2
  • I tried this instead. But it doesn't really work either... I'm not getting really along with the PHP :s Commented Mar 8, 2012 at 20:58
  • I guess you should edit your question and show us how you're calling the shortcode. Oh, and remove the other [box] shortcode. Make small steps first.
    – kaiser
    Commented Mar 8, 2012 at 22:41

Your Answer

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

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