CPT类别-id.php未显示

时间:2017-04-11 20:11:03

标签: php post taxonomy

我创建了2个CPT,以及第一个CPT分类名称类别,以及第二个CPT分类名称gascategory。

使用category-id.php的第一个类别模板正常工作,第二个CPT category-id.php页面模板无法正常工作

CUSTOM REGISTER TAX:

function gas_taxonomies(){

// add new taxonomy     
$labels = array(

'name'              => 'gas_category',
'singular_name'     => 'gas_category',
'search_items'      => 'Search category',
'all_items'         => 'All category',
'parent_item'       => 'Parent category',
'parent_item_colon' => 'Parent category:',
'edit_item'         => 'Edit category',
'update_item'       => 'Update category',
'add_new_item'      => 'Add New category',
'new_item_name'     => 'New category Name',
'menu_name'         => 'Category'
);

$args=array(

'hierarchical'      => true,
'labels'            => $labels,
'show_ui'           => true,
'show_admin_column' => true,
'query_var'         =>  true,
'rewrite'           =>array(
    'slug' => 'gascategory',
));
register_taxonomy('gascategory',array('gas_equipments'),$args );
flush_rewrite_rules();

// add new taxonomy NOT hierarchical

 register_taxonomy('gastag','gas_equipments',array(

'label'             => 'Tag',
'rewrite'           => array ('slug' => 'gastag'),
'hierarchical'      => false
));

}
add_action('init','gas_taxonomies');

<?php get_header(); 
/*
Template Name: Category ID Template
*/
?>

<!-- here loop POST ID -->

<?php
$mypost = array( 'post_type' => 'gas_equipments','cat' => 34);
$loop = new WP_Query( $mypost );
?>



<!-- POST LOOP -->
<div class="row">

<!-- DROPDOWN FILTER-->
<div class="row">



 <div class="col-md-9 row cat-left">

 <div class="row-inner">
 <div class="col-md-5 filter-bot">
 <li id="categories-filter">
 <h3><?php _e( 'Filter By' ); ?></h3>
 <form id="category-select" class="category-select" action="<?php echo           esc_url( home_url( '/' ) ); ?>" method="get">

 <?php
 $args = array(
 'show_option_none' => __( 'Select category' ),
 'show_count'       => 1,'orderby'          => 'name','echo'             => 0, );?>

 <?php $select  = wp_dropdown_categories( $args ); ?>
 <?php $replace = "<select$1 onchange='return this.form.submit()'>"; ?>
 <?php $select  = preg_replace( '#<select([^>]*)>#', $replace, $select );     ?>

 <?php echo $select; ?>

 <noscript>
 <input type="submit" value="View" />
 </noscript>

 </form>
 </li>
 </div>
 </div>



 <?php if ($loop->have_posts()) : while ($loop->have_posts()) :     $loop->the_post(); ?>


    <div class="col-md-4 archive-single-box">

    <div class="archive-single-box-inner">

    <div class="inner-color-half">
    <div class="archive-image-wraper">

    <?php the_post_thumbnail ();?>

    <div class="archive-content">
    <a href="<?php the_permalink() ?>"><h4><?php the_title(); ?></h4></a>



    <span><?php echo custom_cutting_get_terms($post->ID, 'category'); ?></span>
    </div>
    </div>
    </div>
    </div>
    </div>


              <?php endwhile; ?>
                   <?php endif; ?>
    </div>  


    <div class="col-md-3 cat-right">
        <div class="search-form">
        <?php get_template_part( 'searchform' ); ?>
        </div>

        <hr>

        <div class="category-list">
            <?php
                $args = array(
                    'include' => '22,23',
                    'orderby' => 'count',
                        'order' => 'DESC',
                        'number' => 5,
                        'title_li' => 'Cutting System',
                        'show_count' => 1
                    );
                wp_list_categories($args);
                ?>
        </div>


    </div>             

     </div>
     </div>
    </article>  




      <?php get_footer(); ?>

1 个答案:

答案 0 :(得分:0)

工作正常..

$ mypost = array(

'post_type' => 'your post type',
'posts_per_page' => -1,
'tax_query' => array(
    array(
        'taxonomy' => '(register-taxname)',
        'field' => 'slug',
        'terms' => '(category-slugname)'
    )
 )
);