我正在开发一个快捷码函数,它返回一个类别图像、一个指向该类别的链接、该类别中最后三篇文章以及另一个指向该类别的链接。请参见下面的我的代码:
add_shortcode(\'caticons_listing\',\'bm_caticons_listing\');
function bm_caticons_listing($atts) {
extract( shortcode_atts( array(
\'include\' => \'\',
\'exclude\' => \'\',
\'small\' => \'true\'
), $atts ) );
if ($atts[\'include\']) $include = "&include=".$atts[\'include\'];
if ($atts[\'exclude\']) $exclude = "&exclude=".$atts[\'exclude\'];
if ($atts[\'small\'] == \'false\') $small = "&small=false";
$listing_code .= \'<table class="cat-nav">\';
foreach(get_categories("orderby=name&order=ASC&hide_empty=0".$include.$exclude) as $category) {
if (category_description($category->cat_ID)) { $desc = category_description($category->cat_ID); } else { $desc = "Coming soon!";}
if ($category->count > 0) {
$seemore = \'<br /><a href="\'.get_category_link( $category->term_id ).\'">See more.</a>\';}
else {$seemore = \'\';}
query_posts(\'cat=\'.$category->term_id.\'&showposts=3\');
$listing_code .= \'<tr><td>\'.get_cat_icon("echo=false".$small."&class=caticon&cat=".$category->cat_ID).\'</td><td valign="top" style="padding: 5px;"><a href="\'.get_category_link( $category->term_id ).\'"><h2 style="font-size: 130%;">\'.$category->cat_name.\'</h2></a>\'.category_description($category->cat_ID).\'<br />\';
//$listing_code .= "I think I need a loop here.";
$listing_code .= $seemore.\'</td></tr>\';
}
$listing_code .= \'</table>\';
return $listing_code;
}
我的问题是,以WP循环示例的编写方式,我无法找到一种好的方法,以一种可以存储为变量(将作为快捷码输出返回)的方式将三篇最新文章作为链接输出。任何帮助都将不胜感激。谢谢