我寻求一些帮助,列出每个自定义分类法类别的所有帖子标题。这是一个注册到原生wordpress页面的分类法。
请在下面查看我到目前为止所尝试的内容:
我的分类标准添加代码:
function create_topics_hierarchical_taxonomy(){
$labels = array(
'name' => _x( 'alltanks', 'taxonomy general name' ),
'singular_name' => _x( 'Tank Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Tank Categories' ),
'all_items' => __( 'All Tank Categories' ),
'parent_item' => __( 'Parent Tank Category' ),
'parent_item_colon' => __( 'Parent Tank Category:' ),
'edit_item' => __( 'Edit Tank Category' ),
'update_item' => __( 'Update Tank Category' ),
'add_new_item' => __( 'Add New Tank Category' ),
'new_item_name' => __( 'New Tank Category Name' ),
'menu_name' => __( 'Tank Categories' ),
);
register_taxonomy('tanks',array('page'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true
//'rewrite' => array( 'slug' => 'tankcategory' ),
));
}
查询帖子:
<?php
$args = array(
'post_type' => 'post', // or should it be page?
'posts_per_page' => '1',
'order_by' => 'date',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'alltanks',
'field' => 'slug',
'cat' => 49
)
);
$query = new WP_Query( $args );
?>
<?php if (have_posts()) : while( $query->have_posts() ) : $query->the_post(); ?>