我在插件中使用了一个短代码处理程序。短代码可以有不同的(可选)参数。例如,可以在静态WordPress页面上使用两个短代码,在短代码之前、之间和之后都有文本。
例如:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr
<table>
<tr>
<td>[shortcode option="1"]</td>
<td>[shortcode option="2"]</td>
</tr>
</table>
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Sticky Posts:
[shortcode option="3"]
m et justo duo dolores et
我对shortcode处理程序的编码如下:function show_posts_handler( $atts, $content=null, $code="" ) {
//code 4 displaying
extract( shortcode_atts( array(
\'sticky\' => \'false\',
\'latest\' => \'false\',
\'missions\' => \'false\',
\'count\' => \'0\',
), $atts ) );
if($sticky != \'false\')
{
show_sticky_posts();
} else if($latest != \'false\'){
show_lastest_posts($count);
}else if($missions != \'false\'){
show_lastest_missions($count);
}else{
show_all_posts_from_categories();
}
}
add_shortcode( \'show_posts\', \'show_posts_handler\' );
短代码应该在页面的所见即所得编辑器中使用,而不是以编程方式在模板中使用。The problem is "The shortcodes are always displayed before the text".