themosis / framework

The Themosis framework core.
https://framework.themosis.com/
GNU General Public License v2.0
671 stars 121 forks source link

Thumbnail Support #91

Closed nathanaelphilip closed 9 years ago

nathanaelphilip commented 9 years ago

I’ve added thumbnail support to my custom post type, but it’s not showing up in the backend. I’ve added support for post thumbnails and they show up under Posts, but not Products.

// Define the products custom post type
$products = PostType::make('product', 'Products', 'Products')->set(array(
    'public'                => true,
    'show_ui'               => true,
    'publicly_queryable'    => true,
    'supports'              => array('title','editor','author','thumbnail','revisions'),
    'has_archive'           => true,
    'rewrite'               => array('slug' => 'products'),
    'taxonomies'            => array('product_category')
));

// Define the product categories custom taxonomy
$product_categories = Taxonomy::make('product_category', $products->getSlug(), 'Product Categories', 'Product Category')->set(array(
    'public'        => true,
    'rewrite'       => array('slug' => 'products/categories'),
    'query_var'     => false,
    'hierarchical'  => true
));
jlambe commented 9 years ago

You also need to add your custom post type slug into the supports.config.php (which acts as the core add_theme_support function). Add your product to the post-thumbnails parameter like so:

'post-thumbnails' => array('post', 'product'),
nathanaelphilip commented 9 years ago

I feel dumb.

amylashley commented 9 years ago

Hi there. I'm doing something similar, however my custom post type is in a plugin. Even though the post type in the plugin supports thumbnails, I still had to go into the supports.config.php file and add the custom post type there. Is there anyway to avoid this dependency between plugin and framework? Thanks!

jlambe commented 9 years ago

Hi,

you can still call inside your plugin, the add_theme_support('post-thumbnails', array( 'your-cpt' )) function so you can add thumbnails for your custom post type.

The supports.config.php file is only for the theme with pre-populated values. Behind the scenes, it still calls the same add_theme_support() function. Hope this helps.

amylashley commented 9 years ago

Yeh, for some reason that wasn't working. I started out by doing that like normal. And finally I started poking around on Google and found this thread. Once I added the custom post type to the supports.config.php everything was fine. shrug

I'll try testing my plugin outside of Themosis and try to troubleshoot it that way.

jlambe commented 9 years ago

And what happened when de-activating the themosis-theme? Try your plugin with the twenty-fifteen theme and let me know how it works. If there is still an issue, can you open a new issue and post your plugin/custom post type code so I can check?

amylashley commented 9 years ago

I removed the custom post type from supports.config.php. I then activated the twenty-fourteen theme and the featured image shows up just fine on the plugin. I'll open a new issue ticket once my plugin is finished though if you'd like.

jlambe commented 9 years ago

So there is only a call to add_theme_support inside your plugin now? Yes you can still post your issue later so I can review it and check if there is no issue with the framework. Thanks.