function myShortcode($atts) {
extract(shortcode_atts(array('cat' => '',), $atts));
ob_start();
if ($cat == '') { echo "Do Nothing!"; }
$output_string = ob_get_contents();
ob_end_clean();
return $output_string;
}
add_shortcode(mycatlist, myShortcode);
添加以下简称代码后(在后段从可湿性粉剂管理员)
[mycatlist cat=4]
添加以下代码在wordpress模板文件中
<?php echo do_shortcode("[mycatlist]"); ?>
我得到那个输出什么都不做!
,但我想猫值我的意思是4
@Mark。是的,我尝试过,但没有工作 –
我不明白你为什么需要'ob_'在这段代码中。 ::::: *“给我输出”*和*“需要输出”*代表什么? ::::据我所见,第一个例子('[mycatlist cat = 4]')有一个空输出,第二个('do_shortcode(“[mycatlist]”)')应该输出'Do Nothing!' ... – brasofilo
@brasofilo请再次检查我编辑的问题 –