繁体   English   中英

短代码中的短代码 - wordpress

[英]Shortcodes inside a shortcode - wordpress

我创建了一个显示员工的短代码,HTML看起来像这样:

<ul class="employees">

<li><img src=""> <h5>name</h5> <p>description</p></li>
<li><img src=""> <h5>name</h5> <p>description</p></li>
..

</ul>

所以我创建了2个短代码:

[start_employee] - 包含<ul class="employee"> .. </ul>

[员工] - 包含有关员工的内容

它应该像那样工作:

[start_employee]
[employee img=".." name=".." description=".."] 
[employee img=".." name=".." description=".."] 
[/start_employee]

但是当我把它放在wordpress编辑器中时,html看起来像那样:

<ul class="employee">
[employee img=".." name=".." description=".."] 
[employee img=".." name=".." description=".."]
</ul>

我想我知道为什么..因为start_employee的功能包含:

return '<ul class="employee">'.$content.'</ul>';

我应该怎么做才能将它读作短代码?

谢谢。

短代码不会自动嵌套 - 您必须自己调用do_shortcode($content) 请参阅http://codex.wordpress.org/Shortcode_API上的caption_shortcode()示例。

您必须递归使用短代码才能获得结果。

function start_employee($attr,$content){
          return '<ul class="employee">'.do_shortcode($content).'</ul>';
}
add_shortcode("start_employee","start_employee");

function employee($attr,$content){
          return '<li><img src=""> <h5>name</h5>; <p>description</p></li>';
}
add_shortcode("employee","employee");

如果您设置了递归函数,就像在Cart66中一样,您可以执行以下操作:

echo do_shortcode('[hide_from level="membership" ]<strong>You may only order this item if you are a member. Become a <a href="http://yoursite.com/beta/member-log-in/">member</a>.</strong>[/hide_from]');
echo do_shortcode('[show_to level="membership"]'.do_shortcode('[add_to_cart item="'.$prefix.get_post_meta($post->ID,'_et_cart66_product_id',true).'" ]').'[/show_to]');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM