• I have created a custom post type in my functions.php file but need there to be some sort of category option for it for post filtering of the custom post type.

    This is what I have:

    <?php
    
    add_theme_support('post-thumbnails');
    set_post_thumbnail_size( 300, 300, true ); // Normal post thumbnails
    add_image_size( 'featured-post-tumbnail', 800, 460 ); // Permalink thumbnail size
    //-----------register custom post type
      register_post_type( 'portfolio',
        array(
          'labels' => array(
            'name' => __( 'Portfolio' ), //this name will be used when will will call the portfolio in our theme
            'singular_name' => __( 'Portfolio' ),
    		'add_new' => _x('Add New', 'portfolio'),
    		'add_new_item' => __('Add New Project'), //custom name to show up instead of Add New Post. Same for the following
    		'edit_item' => __('Edit Project'),
    		'new_item' => __('New Project'),
    		'view_item' => __('View Projects'),
          ),
          'public' => true,
    	  'show_ui' => true,
    	  'hierarchical' => false, //it means we cannot have parent and sub pages
    	  'capability_type' => 'post', //will act like a normal post
    	  'rewrite' => 'portfolio', //this is used for rewriting the permalinks
    	  'query_var' => false,
    	  'supports' => array( 'title',	'editor', 'thumbnail', 'excerpts', 'revisions', 'custom-fields') //the editing regions that will support
        )
      );
    
    //------enable post thumbnail preview for custom columns
    if ( !function_exists('fb_AddThumbColumn') && function_exists('add_theme_support') ) {
    
    	// for post and portfolio
    
    	function fb_AddThumbColumn($cols) {
    		$cols['thumbnail'] = __('Thumbnail');
    		return $cols;
    	}
    
    	function fb_AddThumbValue($column_name, $post_id) {
    
    			$width = (int) 200;
    			$height = (int) 125;
    
    			if ( 'thumbnail' == $column_name ) {
    				// thumbnail of WP 2.9
    				$thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );
    				// image from gallery
    				$attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') );
    				if ($thumbnail_id)
    					$thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
    				elseif ($attachments) {
    					foreach ( $attachments as $attachment_id => $attachment ) {
    						$thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true );
    					}
    				}
    					if ( isset($thumb) && $thumb ) {
    						echo $thumb;
    					} else {
    						echo __('None');
    					}
    			}
    	}
    
    	// for posts
    	add_filter( 'manage_posts_columns', 'fb_AddThumbColumn' );
    	add_action( 'manage_posts_custom_column', 'fb_AddThumbValue', 10, 2 );
    
    	// for portfolio
    	add_filter( 'manage_portfolio_columns', 'fb_AddThumbColumn' );
    	add_action( 'manage_portfolio_custom_column', 'fb_AddThumbValue', 10, 2 );
    }
    
    //----------------edit custom columns display for back-end
    add_action("manage_posts_custom_column", "my_custom_columns");
    add_filter("manage_edit-portfolio_columns", "my_portfolio_columns");
    
    function my_portfolio_columns($columns) //this function display the columns headings
    {
    	$columns = array(
    		"cb" => "<input type=\"checkbox\" />",
    		"title" => "Work Title",
    		"description" => "Description",
    		"thumbnail" => "Thumbnail"
    	);
    	return $columns;
    }
    
    function my_custom_columns($column)
    {
    	global $post;
    	if ("ID" == $column) echo $post->ID; //displays title
    	elseif ("description" == $column) echo $post->post_content; //displays the content excerpt
    	elseif ("thumbnail" == $column) echo $post->post_thumbnail; //shows up our post thumbnail that we previously created.
    }
    
    ?>

    Pretty much it creates a post type for portfolio items. Porblem is in the template I have created for the portoflio page I am trying to create a filter for different type of portfolio items (websites, logos, etc..) There didn’t seem to be any kind of “supports” array type for categories, so is there something I can do to add some sort of custom drop down in the custom fields section for a category and featured image (for the homepage, not for the portfolio gallery thumbnail) separate from the thumbnail or something?

    Most importantly I want to have the code be easily capable of adding more custom post types if need be.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Post Type Fields and Info’ is closed to new replies.