Custom template for custom taxonomy

90 views Asked by At

I created a custom post type using the following code

// Our custom post type function
function create_posttype() {

register_post_type( 'apps',
// CPT Options
    array(
        'labels' => array(
            'name' => __( 'Apps' ),
            'singular_name' => __( 'App' )
        ),
 'supports'            => array( 'title', 'editor', 'excerpt', 'author',     'thumbnail', 'comments', 'revisions', 'custom-fields', ),
'taxonomies'          => array( 'category' ),

'hierarchical'        => false,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'capability_type'     => 'page',
    )
);
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );

Then i created a category from the backend and a few posts . then i created a taxonomy archive page called taxonomy-category.php and addde the following code

<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>
<h2> Archive for <?php echo $term->name;?></h2>

<?php query_posts(array( 'post_type'=>'apps', 'category' => $term->slug, 'posts_per_page' => -1 )); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

  <!--your content goes here-->

  <!--your content goes here-->

 <?php endwhile; else: ?>
<h3>Sorry, no matched your criteria.</h3>
 <?php endif; ?>

and when i click view on a custom made taxonomy it is showing nothing found.but the default post type categories are working.

Please help.

0

There are 0 answers