我创建了一个自定义帖子类型,名为“whiz_qt_quote
“。自定义帖子类型使用类别。我为所有帖子创建了一个快捷码。”[quote]
.
我想在一个页面上显示一个类别的帖子。因此,不要使用短代码[quote]
, 可能是这样的[quote category="motivation"]
它只会显示“动机”类别的帖子。
目前,我正在使用以下代码作为短代码。我只需要以某种方式添加category属性:
if (!defined(\'ABSPATH\')) exit;
function whiz_qt_feed_shortcode( $atts ) {
extract( shortcode_atts( array( \'limit\' => 3, \'type\' => \'whiz_qt_quote\',\'category\' => \'\'), $atts ) );
global $paged;
$paged = get_query_var(\'paged\') ? get_query_var(\'paged\') : 1;
$args = query_posts( array (
\'posts_per_page\' => $limit,
\'post_type\' => $type,
\'order\' => \'ASC\',
// \'orderby\' =>\'menu_order\',
\'paged\' => $paged ,
\'category_name\' => $category) );
if ( ! empty( $category ) ) {
$args[\'category_name\'] = $category;
}
$list = \' \';
while ( have_posts() ) { the_post();
$list .= \'<article class="listing-view clearfix">\'
. \'<div class="listing-content">\'
. \'<h3><a href="\' . get_permalink() . \'">\' . get_the_title() . \'</a></h3>\'
.\'<p>\' . get_the_excerpt() . \'</p>\'
. \'</div>\'
. \'</article>\';
}
return
\'<div class="listings clearfix">\'
. $list
. \'<div class="nav-previous">\' . get_next_posts_link( __( \'<span class="meta-nav">←</span> Older posts\' ) ) . \'</div>\'
. \'<div class="nav-next">\' . get_previous_posts_link( __( \'Newer posts <span class="meta-nav">→</span>\' ) ) . \'</div>\'
. \'</div>\' .
wp_reset_query();
}
add_shortcode( \'quote\', \'whiz_qt_feed_shortcode\' );
?>`