2017-02-17 58 views
0

蔭使用自定義分類任何自定義信息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後按類別。

回答

0

你爲什麼在上市的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(); 
    } 

    ?> 

希望這會爲你工作。謝謝

+0

我不想顯示所有帖子,我只想選擇的類別帖子。如果我在index.php中選擇一個類別。結果將顯示在taxonimy-template.Thats我需要 –

+0

@VijayKumarB你執行代碼在你的taxonomy-portfolio_category.php?你見過結果嗎? –

+0

ya.But它顯示所有posts.Not所選類別崗位。 –

相關問題