Php 如何在具有不同属性值的页面上多次使用相同的短代码

Php 如何在具有不同属性值的页面上多次使用相同的短代码,php,wordpress,shortcode,wordpress-shortcode,Php,Wordpress,Shortcode,Wordpress Shortcode,所以我基本上需要在同一个页面上使用不同属性值多次使用相同的短代码 因此,在我的页面上,我有以下短代码: [sponsors type="Platinum"] [sponsors type="Premium"] [sponsors type="Plus"] 然后我有多个if语句,它们都声明了以下内容: if ( $atts['type'] == 'Platinum' ) { ?> <h2><?php echo 'working'?></h2> <?

所以我基本上需要在同一个页面上使用不同属性值多次使用相同的短代码

因此,在我的页面上,我有以下短代码:

[sponsors type="Platinum"]
[sponsors type="Premium"]
[sponsors type="Plus"]
然后我有多个if语句,它们都声明了以下内容:

if ( $atts['type'] == 'Platinum' ) {
?>
<h2><?php echo 'working'?></h2>
<?php
} else {}

if ( $atts['type'] == 'Premium' ) {
?>
<h2><?php echo 'working'?></h2>
<?php
} else {}

if ( $atts['type'] == 'Plus' ) {
?>
<h2><?php echo 'working'?></h2>
<?php
} else {}
if($atts['type']=='Platinum'){
?>
如何在具有不同属性值的页面上多次使用相同的短代码

你是如何做到这一点的:

[sponsors type="Platinum"]
[sponsors type="Premium"]
[sponsors type="Plus"]
问题是,短代码不能
回显
内容,它们必须
返回代码中的字符串

像这样:

add_shortcode('sponsors', function($atts,$content){
    if ( $atts['type'] == 'Platinium' ) {
        $result = "<h2>Platinum working</h2>";
    }
    else if ( $atts['type'] == 'Premium' ) {
        $result = "<h2>Premium working</h2>";
    }
    else if ( $atts['type'] == 'Plus' ) {
        $result = "<h2>Plus working</h2>";
    }
    return $result;
});
add_shortcode('赞助商'),函数($atts,$content){
如果($atts['type']=='Platinium'){
$result=“白金工作”;
}
如果($atts['type']=='Premium'){
$result=“高级工作”;
}
else if($atts['type']=='Plus'){
$result=“加上工作”;
}
返回$result;
});

我想你需要一些关于这个的东西。你看到了吗?