Wednesday, 16 December 2015

how to create and display categories for post type in WordPress

function args_ourwork_posttype(){
   $args_services = array(
   'labels'=> array( 'name'=>'ourwork Tab',
       'singular_name'=> 'ourwork',
       'name_admin_bar'=> 'ourwork',
       'all_items' =>'View all ourwork',
       'add_new'=> 'Add New ourwork' ),
   'description' =>"This post type is for ourwork",
   'public' => true,
   'publicly_queryable'=> true,
   'show_ui' => true,
   'show_in_menu'=> true,
   'show_in_admin_bar'=> true,
   'capability_type'=> 'page',
   'menu_icon' => get_stylesheet_directory_uri().'/images/dash-logos.png',
   'supports'=> array( 'title', 'editor', 'author', 'thumbnail', 'excerpt',

register_post_type( "ourwork", $args_services );
    $categories_labels = array(
        'label' => 'ourwork Category',
        'hierarchical' => true,
        'query_var' => true
    register_taxonomy('ourwork_categories', 'ourwork', $categories_labels);





 $args = array(
 'post_type'=> 'ourwork',
 'tax_query' => array(
   'taxonomy' => 'ourwork_categories',
   'field' => 'slug',
   'terms' => 'all'

$my_query = new WP_Query($args);
//$postslist = get_posts( $args_args );

if( $my_query->have_posts() ) {
  while ($my_query->have_posts()) : $my_query->the_post(); ?>

<div class="tab-img col-sm-3">
                 <?php the_post_thumbnail('full'); ?>
  <div class="tab-hover text-center">
  <img src="<?php echo get_stylesheet_directory_uri();?>/images/eyehover.png">
  <div class="link-hover"><?php the_content();?></div>

wp_reset_query();  // Restore global post data stomped by the_post().

No comments:

Post a Comment

Alternative content