0

I know it is easy to add custom fields (meta boxes) to custom post types POSTS. And also I know that if you want to add thumbnail to a post type you should add support for it in register_post_type. but how it is done with custom post type itself (Archive)?

PS: I have read the documentation of register_post_type but found nothing. https://codex.wordpress.org/Function_Reference/register_post_type

5
  • 1
    wouldn't it be better if you say how I'm wrong instead of giving me thumb down?!
    – pouria
    Sep 19, 2016 at 13:12
  • If you review the WordPress documentation on register_post_type() the majority of your question will be answered. You can find that on the WordPress codex at codex.wordpress.org/Function_Reference/register_post_type
    – Steve
    Sep 19, 2016 at 13:16
  • @Stephen I think you have miss understood my friend. I do not need a thumbnail for posts, I want it for the archive and it seems that it is impossible with register_post_type
    – pouria
    Sep 19, 2016 at 13:18
  • 1
    perhaps you should edit your question to clarify and ask a specific question. As it reads it simply looks as if you haven't bothered to read the basic documentation on CPT.
    – Steve
    Sep 19, 2016 at 13:21
  • @Stephen So I will say that I have bothered to read the whole documentation :))
    – pouria
    Sep 19, 2016 at 13:22

2 Answers 2

1

Do you mean something like this?

 $args = array( 'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
    );

This code goes after the function that creates your CPT and before the register_post_type

i.e.

function my_custom_post () {
...
}

$args = array (...)
);

register_post_type ($cpt, $args);
4
  • thanks but no my friend, I want the thumbnail for the Archive, not for the posts.
    – pouria
    Sep 19, 2016 at 13:34
  • I know, but I get it when my answer was published :P Do you have custom taxonomies? What do you have in this line 'taxonomies' => array(...), Sep 19, 2016 at 13:39
  • It has some taxonomies but I think it has no use for this
    – pouria
    Sep 19, 2016 at 13:48
  • I've checked on a template of mine and I did it naming the archive page archive-my_custom_post.php and this <?php the_post_thumbnail('category-thumbnail'); ?> (the CPT uses default categories). Would you share your problem code? ` Sep 19, 2016 at 14:09
1

Archives themselves are not defined using the register_post_type() function, they are simply a display or list of a given post type using the theme's archive page(s) or custom archive page format. The display of a thumbnail or featured image is controlled by the theme or custom archive page(s).

If a CPT is registered to support categories then a thumbnail or featured image can be defined for the given category of the custom post type. But again the display of that category thumbnail is determined by the theme or custom archive page. Not within the CPT itself.

1
  • 1
    And by "page" I believe you mean the archive template, or PHP script used to display that archive page.
    – jdm2112
    Sep 19, 2016 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.