短代码示例:(摘自:GenerateWP: Shortcodes Generator
// Add Shortcode
function img_shortcode( $atts , $content = null ) {
// Attributes
extract( shortcode_atts(
array(
\'width\' => \'\',
\'height\' => \'\',
), $atts )
);
// Code
// This is the line you need to study:
return \'<img src="\' . $content . \'" width="\' . $width . \'" height="\' . $height . \'">\';
}
add_shortcode( \'img\', \'img_shortcode\' );
这是使用的默认[img]标记
phpBB 和其他人作为发布图像的“快捷方式”。请注意,要返回HTML,必须使用原始格式。您不能跨多个函数堆叠输出,即将函数1传递给函数2,并期望函数2被函数1的内容重载。
UPDATE
使用我之前给你的示例,我将其拼凑在一起,我不能保证它会按照我预期的方式运行,也没有办法添加图像,除非手动:
// Add Shortcode
function automatic_ads_shortcode( $atts , $content = null ) {
// Attributes
extract( shortcode_atts(
array(
\'width\' => \'\',
\'height\' => \'\',
), $atts )
);
// Code
// Set the $image_array base_dir to the Media Library Path
define(\'IMAGES_PATH\', dirname(realpath(\'/wp-content/uploads/\')));
//Ad Rotator
//Array of Ads
//Manually add your ad images to this array. Due
//to the functionality of a Shortcode, there is no
//way to accept user input. You\'d need a plugin
//for that.
$image_array = array(IMAGES_PATH . \'img1.jpg\',
IMAGES_PATH .\'img2.jpg\',
IMAGES_PATH .\'img_x.jpg\');
$current_week = date(W);
// Shuffling + Random ensures we don\'t
// get the same image twice in a row.
// Every 8 Weeks = 2 months
if ($current_week % 8 == 0)
{
$shuffled_array = shuffle($image_array);
$chosen_image = array_rand($shufled_array,1);
}
//Every 4 Weeks = 1 month
elseif ($current_week % 4 == 0)
{
$shuffled_array = shuffle($image_array);
$chosen_image = array_rand($shufled_array,1);
}
// All other Cases
else {
$chosen_image = array_rand($image_array,1);
}
//Output Line
return \'<img src="\' . $chosen_image . \'" width="\' . $width . \'" height="\' . $height . \'">\';
}
add_shortcode( \'auto_ads\', \'automatic_ads_shortcode\' );
测试完毕后,使用短代码[自动\\u广告],并将所述短代码添加到广告通常出现的部分。如您所见,我坚持您不能堆叠输出的观点。