看看category post shortcode 下面是一个插件,稍作修改即可调用您的帖子类型和分类法:
// Taxonomy category shortcode
function cat_func($atts) {
extract(shortcode_atts(array(
\'class_name\' => \'cat-post\',
\'totalposts\' => \'-1\',
\'category\' => \'\',
\'thumbnail\' => \'false\',
\'excerpt\' => \'true\',
\'orderby\' => \'post_date\'
), $atts));
$output = \'<div class="\'.$class_name.\'">\';
global $post;
$args = array(
\'posts_per_page\' => $totalposts,
\'orderby\' => $orderby,
\'post_type\' => \'inventory\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'inventory-category\',
\'field\' => \'slug\',
\'terms\' => array( $category)
)
));
$myposts = NEW WP_Query($args);
while($myposts->have_posts()) {
$myposts->the_post();
$output .= \'<div class="cat-post-list">\';
if($thumbnail == \'true\') {
$output .= \'<div class="cat-post-images">\'.get_the_post_thumbnail($post->ID, \'thumbnail\').\'</div>\';
}
$output .= \'<div class="cat-content"><span class="cat-post-title"><a href="\'.get_permalink().\'">\'.get_the_title().\'</a></span>\';
if ($excerpt == \'true\') {
$output .= \'<span class="cat-post-excerpt">\'.get_the_excerpt().\'</span>\';
}
$output .= \'</div>
<div class="cat-clear"></div>
</div>\';
};
$output .= \'</div>\';
wp_reset_query();
return $output;
}
add_shortcode(\'inventory-category\', \'cat_func\');
usage:
只需在你的帖子或页面中添加此短代码
[inventory-category totalposts="3" category="bulk-racks" thumbnail="true" excerpt="true" ]
totalposts—要显示的帖子总数。默认值为-1 category-category slug。对于多个Slug缩略图,请使用逗号-如果要显示缩略图,请设置为true。默认值为false
摘录-如果要显示摘录,请将其设置为true。默认值为true-您的帖子将按排序。默认post\\u日期。检查http://codex.wordpress.org/Template_Tags/get_posts 有关详细信息