• Resolved sarscott

    (@sarscott)


    HI there,

    I’ve been going round in circles for ages here. I hope someone can help!

    I have a custom post type called “showroom’. Here is the code

    <?php
    function register_showroom_post_type() {
        $labels = array(
        'name'               => _x( 'Showroom Cars', 'post type general name' ),
        'singular_name'      => _x( 'Showroom Car', 'post type singular name' ),
        'add_new'            => _x( 'Add Showroom Car'  ),
        'add_new_item'       => __( 'Add New Showroom Car' ),
        'edit_item'          => __( 'Edit Showroom Car' ),
        'new_item'           => __( 'New Showroom Car' ),
        'all_items'          => __( 'All Showroom Cars' ),
        'view_item'          => __( 'View Showroom Car' ),
        'search_items'       => __( 'Search Showroom Listings' ),
        'not_found'          => __( 'No Showroom listings found' ),
        'not_found_in_trash' => __( 'No Showroom listings found in the Trash' ),
        'parent_item_colon'  => '',
        'menu_name'          => 'Showroom Cars',
      );
      $args = array(
        'labels'        => $labels,
        'description'   => 'Holds the showroom cars and specific data',
        'public'        => true,
        'menu_position' => 5,
        'supports'      => array( 'title', 'thumbnail' ),
        'has_archive'   => true,
        'menu_icon'     => 'dashicons-admin-network',
      );
      register_post_type( 'showroom', $args );
    }
    add_action( 'init', 'register_showroom_post_type' );
    
    function showroom_updated_messages( $messages ) {
      global $post, $post_ID;
      $messages['showroom'] = array(
        0 => '',
        1 => sprintf( __('Car listing updated. Nice one. <a href="%s">View Car</a>'), esc_url( get_permalink($post_ID) ) ),
        2 => __('Custom field updated.'),
        3 => __('Custom field deleted.'),
        4 => __('Car listing updated.'),
        5 => isset($_GET['revision']) ? sprintf( __('Car listing restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
        6 => sprintf( __('Car listing published. Sell that beast! <a href="%s">View the listing</a>'), esc_url( get_permalink($post_ID) ) ),
        7 => __('Car listing saved.'),
        8 => sprintf( __('Car listing submitted. <a target="_blank" href="%s">Preview car listing</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
        9 => sprintf( __('Car listing scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview car listing</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
        10 => sprintf( __('Car listing draft updated. <a target="_blank" href="%s">Preview Car listing</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
      );
      return $messages;
    }
    add_filter( 'post_updated_messages', 'showroom_updated_messages' );
    
    function taxonomies_showroom() {
      $labels = array(
        'name'              => _x( 'Car Manufacturers', 'taxonomy general name' ),
        'singular_name'     => _x( 'Car Manufacturer', 'taxonomy singular name' ),
        'search_items'      => __( 'Search Car Manufacturers' ),
        'all_items'         => __( 'All Car Manufacturers' ),
        'parent_item'       => __( 'Parent Car Manufacturer' ),
        'parent_item_colon' => __( 'Parent PCar Manufacturer:' ),
        'edit_item'         => __( 'Edit Car Manufacturer' ),
        'update_item'       => __( 'Update Car Manufacturer' ),
        'add_new_item'      => __( 'Add New Car Manufacturer' ),
        'new_item_name'     => __( 'New Car Manufacturer' ),
        'menu_name'         => __( 'Car Manufacturers' ),
        'show_ui'           => true,
      );
      $args = array(
        'labels' => $labels,
        'hierarchical' => true,
      );
      register_taxonomy( 'car_manufacturers', 'showroom', $args );
    }
    add_action( 'init', 'taxonomies_showroom', 0 );
    
    ?>

    This creates a admin panel etc and I can create posts fine. I have a single-showroom.php file that displays the post type fine.

    I want to create a template page that displays only this post type. So I created this very basic page to test this

    <?php
        /**
        *Template Name: Showroom 2
        *Description: Creates a gallery of featured images from the showroom post type
        */
    
        get_header();
    ?>
    
    <p>SHOWROOM 2 PAGE</p>
    
    <?php
    $args = array( 'post_type' => 'showroom', 'posts_per_page' => 10 );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
        the_title();
        echo '<div class="entry-content">';
        the_content();
        echo '</div>';
    endwhile;
    ?>
    
    <?php get_footer(); ?>

    Ive created a Showroom page and set the template to “Showroom 2” but, this page isn’t displayed. Instead the archive.php page is shown.

    I have another custom post type called “auction” and when tested with this template file displays “auction” titles fine. So this leads me to think I’ve got something wrong in the post type creation. I can’t see it!

    Why isn’t my Showroom post type showing with this template?
    Can anyone help?

    Thanks in advance.

    S

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter sarscott

    (@sarscott)

    Perhaps I’m doing this wrong.

    Can someone answer me this…

    If I want to create a page to display one custom post type and style how that post type is displayed e.g grid etc.

    Do I make a Archive page for that post type and build the structure in there?
    OR
    A Template file for the Page I created in my admin panel?

    Thanks

    Thread Starter sarscott

    (@sarscott)

    Upon further investigation this problem is only happening when I set Permalinks to “Post name”. If I select “Numeric” for example, the template file is displayed.

    Does anyone know why that might be?

    Thread Starter sarscott

    (@sarscott)

    Ok so for anyone reading this…

    I changed my custom post type from ‘showroom’ to ‘car’ and made the various adjustments (single template name etc) all is fine!

    Only lost about a day of my life 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom post type – Template page not being found’ is closed to new replies.