我使用这种结构来实现自己的短代码:
function column_with_icon($atts, $content = null) {
extract(shortcode_atts(array(
\'icon\' => \'onebit_03\'
), $atts));
return \'<div class="column3">
<img class="features-icon" alt="icon" src="\' . get_bloginfo("template_url") . \'/images/icons/\' . $icon . \'.png"/>
<div class="feature-content">\' . $content . $icon . \'</div>\';
}
add_shortcode(\'column-icon\', \'column_with_icon\');
当我尝试添加这样的内容时:
[column-icon icon="onebit_13"]
<h3>What is Lorem ipsum?</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
<a href="#" class="main-theme-link">Learn more</a></div>
[/column-icon]
“icon”属性的默认值未被覆盖,我得到的值等于“onebit\\u 03”,而不是“onebit\\u 13”,对此我能做些什么?
UPDATE以下是我用来检索和显示数据的代码:
function skible_load_special_offer_section() {
$content = get_option("prc_speciall_offer_text", true);
if (get_option("prc_show_special_offer_section")) {
echo stripslashes(do_shortcode(\'<!--Start Special offer (in border) content-->
<div class="border-top"></div>
<div class="border-middle">
<div class="special-offer-area">
<div class="special-offer-image-left">
<img alt="image" src="\' . get_bloginfo("template_url") . \' /colors/magic_night/special-offer-image.png"/>
</div>
<div class="special-offer-content-right">\' . $content . \'</div>
<div class = "clear"></div>
</div>
</div>
<div class = "border-bottom"></div>
<!--End Special offer (in border) content-->\'));
}
}
SO网友:Rarst
我不知道你的设置出了什么问题。很明显,短代码已正确注册,但某些特定情况会阻止正确解析它。
这是一段测试代码,大致复制了如何解析短代码以执行:
$content = get_option("prc_speciall_offer_text", true);
$pattern = \'/\'.get_shortcode_regex().\'/s\';
preg_replace_callback( $pattern, \'var_dump\', $content );
阵列输出应符合以下要求:
get_shortcode_regex()
规格:
1/6-一个额外的[或],允许用双[[]转义短码
2-短代码名称
3-shortcode参数列表
4-自动关闭/
5-封装某些内容时的短代码内容。
这就是它为我倾倒的东西:
array
0 => string \'[column-icon icon="onebit_13"]
<h3>What is Lorem ipsum?</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
<a href="#" class="main-theme-link">Learn more</a></div>
[/column-icon]\' (length=389)
1 => string \'\' (length=0)
2 => string \'column-icon\' (length=11)
3 => string \' icon="onebit_13"\' (length=17)
4 => string \'\' (length=0)
5 => string \'
<h3>What is Lorem ipsum?</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
<a href="#" class="main-theme-link">Learn more</a></div>
\' (length=345)
6 => string \'\' (length=0)