分类模板没有显示使用have_posts()为自定义后
问题描述:
荫使用自定义分类任何自定义信息type.If我的类目点击使用创建texanomy.It导航到分类模板,但显示所选category.Can一无所知交任何一项帮助我。 显示URL作为URL // portfolio_category /蟋蟀/分类模板没有显示使用have_posts()为自定义后
function.php
add_action('init', 'create_team_post_type');
function create_team_post_type() {
register_post_type('portfolio',
array(
'labels' => array(
'name' => __('Portfolio'),
'singular_name' => __('Portfolio')
),
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'taxonomies' => array('portfolio_category'),
'supports' => array('title','editor','thumbnail')
)
);
}
function taxonomies_portfolio() {
$labels = array(
'name' => _x('Portfolio categories', 'taxonomy general name'),
'singular_name' => _x('Portfolio categories', 'taxonomy singular name'),
'search_items' => __('Query portfolio categories'),
'all_items' => __('All portfolio categories'),
'parent_item' => __('Parent category'),
'parent_item_colon' => __('Parent category:'),
'edit_item' => __('Edit portfolio category'),
'update_item' => __('Update portfolio category'),
'add_new_item' => __('Add Edit portfolio category'),
'new_item_name' => __('New portfolio category'),
'menu_name' => __('Categories'),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'rewrite' => true
);
register_taxonomy('portfolio_category', 'portfolio', $args);
}
add_action('init', 'taxonomies_portfolio', 0);
的index.php
<?php
$defaults = array(
'hide_empty' => false,
'taxonomy' => 'portfolio_category',
'title_li' => __('Categories')
);
wp_list_categories($defaults); ?>
分类法portfolio_category.php
<?php
if(have_posts()):while(have_posts()):the_post();
the_title();
endwhile;
endif;
?>
我需要this.How解决方案可以用我分类filted后按类别。
答
你为什么在上市的index.php的类别。我没有深入。
在分类学portfolio_category.php,
<?php
$taxonomies = get_taxonomies();
foreach ($taxonomies as $taxonomy) {
if($taxonomy = 'portfolio_category'){
$terms['trm'] = get_terms($taxonomy, array('hide_empty'=> false,
'taxonomy'=> 'portfolio_category',
'title_li'=> __('Categories'));
}
}
foreach ($terms['trm'] as $term){
$query = new WP_Query(
array(
'post_type' => 'portfolio',
'tax_query' => array(
array(
'taxonomy' => 'taxonomy',
'field' => 'name',
'terms' => $term->name,
),
),
)
);
if($query->have_posts()):while($query->have_posts()):$query->the_post(); ?>
<h1><?php the_title(); ?></h1> <!-- place html code here -->
<?php
endwhile;
endif;
wp_reset_postdata();
}
?>
希望这会为你工作。谢谢
我不想显示所有帖子,我只想选择的类别帖子。如果我在index.php中选择一个类别。结果将显示在taxonimy-template.Thats我需要 –
@VijayKumarB你执行代码在你的taxonomy-portfolio_category.php?你见过结果吗? –
ya.But它显示所有posts.Not所选类别岗位。 –