Custom post types & Thumbnails

I am looking to set up 2 custom post types - Publicity Management

What I would like to do is display the featured thumbnail for each post from the custom post type on the Publicity page. These will then link though to each post using a custom template.

I would like to do the exact same for the Management section. I have created the post type, but when I click on the thumbnails I am being taken to a page that doesn't contain any of the relevant info.

I am using a child theme of Twenty Twelve.

Can someone please help with this?

Code used for cpt registration

add_action('init', 'publicity_register');  

function publicity_register() {    
  $labels = array(
    //the (probably plural) name for our new post type
    'name' = _x('Publicity', 'post type general name'),
    //how you’d refer to this in the singular (such as ‘Add new ****’) 
    'singular_name' = _x('Publicity', 'post type singular name'),
    'add_new' = _x('Add New', 'publicity'),
    'add_new_item' = __('Add New Publicity Artist'),
    'edit_item' = __('Edit Publicity Artist'),
    'new_item' = __('New Publicity Artist '),
    'view_item' = __('View Publicity Artist'),
    'search_items' = __('Search Publicity'),
    'not_found' =  __('Nothing found'),
    'not_found_in_trash' = __('Nothing found in Trash'),
    'parent_item_colon' = ''
  );
  $args = array(    
    'labels' = $labels,      
    'public' = true,    
    'show_ui' = true,    
    'capability_type' = 'post',    
    'hierarchical' = false,    
    'rewrite' = true,    
    'supports' = array('title', 'editor', 'thumbnail'),
    'has_archive' = true,
  );
  register_post_type( 'publicity' , $args );    
}

Code used for loop

$args = array( 'post_type' = 'publicity', 'posts_per_page' = 20 );
$loop = new WP_Query( $args );
while ( $loop-have_posts() ) : $loop-the_post();
  echo 'div class=col-md-3 portfolio-item';
  echo 'a href=' . get_permalink() . ' title=' . get_the_title() . '';
  echo get_the_post_thumbnail() . ' /a';
  echo 'div class=artist-namea href=' . get_permalink() . ''; 
  echo ' title=' . get_the_title() . '' . get_the_title() . '/a/div';
  echo '/div';
endwhile;
?

Topic post-type-support custom-post-types Wordpress

Category Web


It sounds like you're wanting the page you are redirected to to display the CPT's information in a certain way or format, in which case you'll want to create a single page template for the custom post types you've created.

You can use the single.php file as an example for the layout and customize it as necessary, but the name of the file should be single-publicity.php and single-management.php.

I hope that helps!

Edit

I forgot to mention, I don't know what the name of the page is that you're looping the CPTs through, but make sure the permalinks don't conflict (e.g. a page called Publicity with a slug of publicity).

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.