您好,我对短代码编程相当陌生,想知道是否可以使用不同的短代码标记处理以下嵌套的短代码:
[review]
[title]Sample Review[/title]
[image]http://localhost/wordpress/wp-content/uploads/2016/04/picture.jpg[/image]
[criteria title="Criteria 1" score="100"]
[criteria title="Criteria 2" score="90"]
[criteria title="Criteria 3" score="80"]
[/review]
要生成此预期html块,请执行以下操作:
<section id="review">
<div class="review-top">
<h2>Sample Review</h2> <!--Content of [title][/title]-->
</div>
<div class="review-left">
<img src="http://localhost/wordpress/wp-content/uploads/2016/04/picture.jpg"> <!--Content of [image][/image]-->
</div>
<div class="review-criteria">
<h3>Criteria 1 - 100</h3> <!--Attribute of [criteria]-->
</div>
<div class="review-criteria">
<h3>Criteria 2 - 90</h3> <!--Attribute of [criteria]-->
</div>
<div class="review-criteria">
<h3>Criteria 3 - 80</h3> <!--Attribute of [criteria]-->
</div>
<div class="review-summary">
<h2>90</h2> <!--Average of Criteria 1-3\'s score-->
</div>
</section>
我知道我必须递归地使用do\\u短代码($content),但这样做将调用$contents中的所有短代码,并将产生以下结果:
<section id="review">
<div class="review-top">
<h2>Sample Review</h2> <!--Content of [title][/title]-->
<img src="http://localhost/wordpress/wp-content/uploads/2016/04/picture.jpg"> <!--Content of [image][/image]-->
<div class="review-criteria">
<h3>Criteria 1 - 100</h3> <!--Attribute of [criteria]-->
</div>
<div class="review-criteria">
<h3>Criteria 2 - 90</h3> <!--Attribute of [criteria]-->
</div>
<div class="review-criteria">
<h3>Criteria 3 - 80</h3> <!--Attribute of [criteria]-->
</div>
</div>
...
</section>
短代码如下:
function makeTitle( $atts, $content = null ) {
return \'<h2>\'.$content. \'</h2> <!--Content of [title][/title]-->\';
}
add_shortcode(\'title\', \'makeTitle\');
function makeImage( $atts, $content = null ) {
return \'<img src="\'.$content.\'"> <!--Content of [image][/image]-->\';
}
add_shortcode(\'image\', \'makeImage\');
function makeCriteria( $atts, $content = null ) {
extract(shortcode_atts(
array(
\'title\' => \'Criteria\',
\'score\' => \'0\',
), $atts ));
return \'<div class="review-criteria">
<h3>\'.$title. \' - \' .$score. \'</h3> <!--Attribute of [criteria]-->
</div>\';
}
add_shortcode(\'criteria\', \'makeCriteria\');
function makeReview( $atts , $content = null ) {
return \'<section id="review"><div class="review-top">\'.do_shortcode($content).\'</div></section>\';
...
}
add_shortcode(\'review\', \'makeReview\');
我想做的是在第一个do\\u shortcode($content)上,它应该只对[title][/title]执行do\\u shortcode。非常感谢!