我为页面添加了类别支持
在函数中。php:
function add_categories_to_pages() {
register_taxonomy_for_object_type( \'category\', \'page\' );
}
add_action( \'init\', \'add_categories_to_pages\' );
我创建了“saloane”类别,我有添加了“saloane”类别的页面
在家里。php:
$saloane_q = new WP_Query ( array(\'post_type\' => \'page\', \'category\' => \'saloane\' ));
if ($saloane_q->have_posts()) :
while ($saloane_q->have_posts()) : $saloane_q->the_post();
echo \'<div class="f3">\';
the_post_thumbnail(\'hr_medium\');
echo \'<h2>\';
the_title();
echo \'</h2>\';
the_excerpt();
echo \'</div>\';
endwhile;
endif;
wp_reset_postdata();
?>
应仅显示类别为“saloane”的页面,但应显示所有页面
我还尝试了:
$saloane_q = new WP_Query ( array(\'post_type\' => \'page\', \'category\' => 11 ));
$saloane_q = new WP_Query ( array(\'post_type\' => \'page\', \'cat\' => 11 ));
同样的结果。
使用:
$saloane_q = new WP_Query ( array(\'post_type\' => \'page\', \'category_name\' => \'saloane\' ));
不显示anithyng
如果我不用post_type
像这样:
$saloane_q = new WP_Query ( array(\'category\' => 11 ));
$saloane_q = new WP_Query ( array(\'cat\' => 11 ));
它显示帖子。