你好Wordpress Stack,
我无法将自定义帖子显示在自定义类别下。
所讨论的职位是:
register_post_type(\'feature_article\',
array(
\'labels\' => array(/* left out for clarity */),
\'query_var\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => false,
\'supports\' => array(\'thumbnail\', \'title\', \'excerpt\'),
\'public\' => true,
\'has_archive\' => true,
\'menu_position\' => 5,
\'taxonomies\' => array(\'twin\')
)
);
注册分类如下:
add_action( \'init\', \'twin_post_taxonomy\', 0 );
function twin_post_taxonomy() {
$labels = array(/* for clarity */ );
$args = array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'twin\' ),
);
register_taxonomy( \'twin\', array( \'feature_article\',\'post\'), $args );
}
我想把这篇有问题的帖子称为“双面肖像”:
<?php $args = array( \'post_type\' => \'feature_article\', \'posts_per_page\' => 1, \'article_genre\' => $str, \'orderby\' => \'modified\');
$loop = new WP_Query($args); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php if ( in_category(\'double portrait\') ) {
echo the_title();
} else {
echo the_excerpt();
} ?>
<?php endwhile; wp_reset_postdata(); ?>
抱歉,代码太长太乱了:/
编辑:我得到的是输出摘录,而不是标题。