<?php
if( !function_exists('portfolio_register') ){
function portfolio_register() {
	global $petcare_plugin_name;
	$pf_slug_name = get_theme_mod('pf_slug_name') ? get_theme_mod('pf_slug_name') :'Portfolio';
	$labels = array(
		'name'				=> ucwords($pf_slug_name),
		'singular_name'		=> ucwords($pf_slug_name),
		'add_new'			=> __('Add New Post',$petcare_plugin_name),
		'add_new_item'		=> __('Add New Post',$petcare_plugin_name),
		'edit_item'			=> __('Edit Post',$petcare_plugin_name),
		'new_item'			=> __('New Portfolio Post Item',$petcare_plugin_name),
		'view_item'			=> __('View Portfolio Item',$petcare_plugin_name),
		'search_items'		=> __('Search Portfolio Items',$petcare_plugin_name),
		'not_found'			=> __('Nothing found',$petcare_plugin_name),
		'not_found_in_trash'=> __('Nothing found in Trash',$petcare_plugin_name),
		'parent_item_colon'	=> ''
	);
 
	$args = array(
		'labels'			=> $labels,
		'public'			=> true,
		'exclude_from_search'=> false,
		'show_ui'			=> true,
		'capability_type'	=> 'post',
		'hierarchical'		=> false,
		'rewrite' => array( 'slug' => 'portfolios', 'with_front' => false ),
		'query_var'			=> false,	
		'menu_icon'			=> 'dashicons-portfolio',  		
		'supports'			=> array('title', 'editor', 'excerpt', 'thumbnail', 'comments', 'page-attributes')
	); 
	register_post_type( 'portfolio' , $args );
	//register_taxonomy_for_object_type('post_tag', 'portfolio');
}
add_action('init', 'portfolio_register');
function pf_register_taxonomy() {
 global  $post;
 $pf_slug_name = get_theme_mod('pf_slug_name') ? get_theme_mod('pf_slug_name') :'Portfolio';
// set up labels
$labels = array(
 'name' => ucwords($pf_slug_name) .'Categories',
 'singular_name' =>  ucwords($pf_slug_name) .'Categories',
 'search_items' => 'Search '.ucwords($pf_slug_name).' Categories',
 'all_items' => 'All '.ucwords($pf_slug_name).' Categories',
 'edit_item' => 'Edit '.ucwords($pf_slug_name).''.ucwords($pf_slug_name).' Category',
 'update_item' => 'Update '.ucwords($pf_slug_name).' Category',
 'add_new_item' => 'Add New '.ucwords($pf_slug_name).' Category',
 'new_item_name' => 'New '.ucwords($pf_slug_name).' Category',
 'menu_name' => ucwords($pf_slug_name).' Categories'
);
// register taxonomy
register_taxonomy( 'portfolio_category', 'portfolio', array(
 'hierarchical' => true,
 'labels' => $labels,
 'query_var' => true,
 'show_admin_column' => true
));
}
add_action( 'init', 'pf_register_taxonomy' );
function my_columns($columns) {
	$columns['portfolio_category'] = __('Category','atp_admin');
    $columns['thumbnail'] =  __('Post Image','atp_admin');

    return $columns;
}

function manage_portfolio_columns($name) {
    global $post;global $wp_query;
    switch ($name) {
	 case 'portfolio_category':
               $terms = get_the_terms($post->ID, 'portfolio_category');

        //If the terms array contains items... (dupe of core)
        if ( !empty($terms) ) {
            //Loop through terms
            foreach ( $terms as $term ){
                //Add tax name & link to an array
                $post_terms[] = esc_html(sanitize_term_field('name', $term->name, $term->term_id, '', 'edit'));
            }
            //Spit out the array as CSV
            echo implode( ', ', $post_terms );
        } else {
            //Text to show if no terms attached for post & tax
            echo '<em>No terms</em>';
        }
				break;
        case 'thumbnail':
          
				echo the_post_thumbnail(array(100,100));
				break;
       
    }
}
add_action('manage_posts_custom_column', 'manage_portfolio_columns', 10, 2);
add_filter('manage_edit-portfolio_columns', 'my_columns');
}
?>