1
votes

I am new at WordPress, I created a Custom Post Type, but even after adding "page-attributes" I do not see the template dropdown for choosing my custom template only "Order" field is visible.

My theme has 3 different menus(top, main and footer) where all these menus have same templates for each menu, for example: the main menu has central, east, west, north and south location, have the same layout, same for Top menu as well.

Each location in the main menu and Top menu is an archive page, where I can show the listing of that location posts for further viewing. But by following the conventional archive-{post_type}.php I have to create a new archive page for each location.

Here is the code for main menu:

[
    "capability_type" => "post",
    "description" => "Holds our location's specific data",
    "public" => true,
    "menu_position" => 5,
    "has_archive" => true,
    "show_admin_column" => true,
    "supports" => [
        "title",
        "editor",
        "thumbnail",
        "excerpt",
        "revisions",
        "page-attributes"
    ],
    "taxonomies" => [
        "post_tag"
    ],
    "labels" => [
        "name" => "Locations",
        "singular_name" => "Location",
        "add_new" => "Add Location",
        "add_new_item" => "Add Location" ,
        "edit_item" => "Edit Location",
        "new_item" => "New Location",
        "all_items" => "Locations" ,
        "view_item" => "View Location",
        "search_items" => "Search Location",
        "not_found" => "No Locations found",
        "not_found_in_trash" => "No Locations found in the Trash",
        "parent_item_colon" => "",
        "menu_name" => "Locations"
    ]
]

Here is the output:

enter image description here

Please help in fixing this issue.

Thanks

2

2 Answers

6
votes

Previously this was only available to pages. But as of 4.7 it's available for all post types, you just need to add Template Post Type to the file header.

eg.

<?php
/*
Template Name: Full-width layout
Template Post Type: post, page, product
*/

// … your code here

https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/

0
votes

Make sure on the template file you have created, that you have the following code at the very top:

/**
* Template Name: Test Template
*/

If this does not fix the issue, make sure than inside your theme folder, you have an index.php and style.css files.