代码之家  ›  专栏  ›  技术社区  ›  Mr.Singh PHP Worm...

缺少WordPress自定义文章类型选择模板下拉列表

  •  0
  • Mr.Singh PHP Worm...  · 技术社区  · 7 年前

    “我的主题”有3个不同的菜单(顶部、主菜单和页脚),所有这些菜单对每个菜单都具有相同的模板,例如:主菜单具有中心、东、西、北和南位置,具有相同的布局,顶部菜单也具有相同的布局。

    主菜单和顶部菜单中的每个位置都是一个归档页面,在这里我可以显示该位置帖子的列表以供进一步查看。但是通过遵循传统的archive-{post_type}.php,我必须为每个位置创建一个新的归档页面。

    以下是主菜单的代码:

    [
        "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"
        ]
    ]
    

    输出如下:

    enter image description here

    请帮助解决此问题。

    2 回复  |  直到 7 年前
        1
  •  3
  •   ngearing    7 年前

    以前这只适用于 pages . 但截至 4.7 它适用于所有帖子类型,您只需添加 Template Post Type 到文件头。

    <?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/

        2
  •  0
  •   Declan Kay    7 年前

    确保在创建的模板文件的最上面有以下代码:

    /**
    * Template Name: Test Template
    */
    

    如果这不能解决问题,请确保主题文件夹中有index.php和style.css文件。