我有一个 MySql 表,我在其中放置了一些值:id、机会名称、机会类别、佣金等。现在我需要(自动)创建一个短代码来调用这些值赢得一个数组,例如,如果我写[opportunity id="1"]
wordpress 在数据库中有机会展示横幅id=1
。
这是我的代码
function opportunity_banner_shortcode($atts) {
extract(shortcode_atts(array("id" => ''), $atts));
global $table_prefix, $wpdb, $user_level;
$table_name = $table_prefix . "opportunities";
$finds = $wpdb->get_results("SELECT * FROM {$table_name}", ARRAY_A);
if(sizeof($finds)){
foreach($finds as $find)
return "<a href='" . $find["opp_link"].
"'><img src='" . $find["opp_banner_preview"]."'></a> ";
}
}
add_shortcode('opportunity', 'opportunity_banner_shortcode');
谢谢大家