无法呈现单个CustomPostType.php文件

时间:2017-10-11 作者:JJ BOBO

我有如下CPT和自定义分类插件

function gen_service_tax() {

    $labels = array(
        \'name\'                       => \'Service Types\',
        \'singular_name\'              => \'Service Type\',
        \'menu_name\'                  => \'Service Types\',
        \'all_items\'                  => \'All Service Types\',
        \'parent_item\'                => \'Service Parent\',
        \'parent_item_colon\'          => \'ServicebParents:\',
        \'new_item_name\'              => \'New Service Name\',
        \'add_new_item\'               => \'Add New Service\',
        \'edit_item\'                  => \'Edit Service\',
        \'update_item\'                => \'Update Service\',
        \'separate_items_with_commas\' => \'Separate Services with commas\',
        \'search_items\'               => \'Search Services\',
        \'add_or_remove_items\'        => \'Add or remove Services\',
        \'choose_from_most_used\'      => \'Choose from the most used Services\',
        \'not_found\'                  => \'Service Not Found\',
    );
    $args = array(
        \'labels\'                     => $labels,
        \'hierarchical\'               => true,
        \'public\'                     => true,
        \'show_ui\'                    => true,
        \'show_admin_column\'          => true,
        \'show_in_nav_menus\'          => true,
        \'show_tagcloud\'              => true,
    );
    // This the name tha can be used in Taxonomy cpt collection services
    register_taxonomy( \'services\', array( \'services_cpt\' ), $args );

}

add_action( \'init\', \'gen_service_tax\', 0 );

function gen_services_cpt() {

    $labels = array(
        \'name\'                => \'Services\',
        \'singular_name\'       => \'Service\',
        \'menu_name\'           => \'Services\',
        \'name_admin_bar\'      => \'Services\',
        \'parent_item_colon\'   => \'Service Parent:\',
        \'all_items\'           => \'All Services\',
        \'view_item\'           => \'View Service\',
        \'add_new_item\'        => \'Add New Service\',
        \'add_new\'             => \'Add New Service\',
        \'new_item\'            => \'New Service\',
        \'edit_item\'           => \'Edit Service\',
        \'update_item\'         => \'Update Service\',
        \'search_items\'        => \'Search Services\',
        \'not_found\'           => \'Service Not found\',
        \'not_found_in_trash\'  => \'Service Not found in Trash\',
    );
    $args = array(
        \'description\'         => \'This Post Type Adds Services to Website\',
        \'labels\'              => $labels,
        \'supports\'            => array( \'title\', \'editor\'),
        \'taxonomies\'          => array( \'service_tax\' ),
        \'hierarchical\'        => true,
        \'public\'              => true,
        \'show_ui\'             => true,
        \'show_in_menu\'        => true,
        \'show_in_nav_menus\'   => true,
        \'show_in_admin_bar\'   => true,
        \'menu_position\'       => 5,
        \'rewrite\'             => array( \'slug\' => \'Services\',\'with_front\' => true, \'hierarchical\' => true ),
        \'can_export\'          => true,
        \'has_archive\'         => true,
        \'exclude_from_search\' => false,
        \'publicly_queryable\'  => true,
        \'capability_type\'     => \'post\',
    );
    register_post_type( \'services_cpt\', $args );
}

add_action( \'init\', \'gen_services_cpt\', 0 );
我在主题文件夹中也有此文件格式

单一服务。php单个。php分类服务。php

enter image description here

我还启用了Post name http://vancouvermetalworks.ca/sample-post/ wp选项Permalink Settings ,也但当我创建一个新的帖子类型时,wp首先导航到single.php 而不是single-services.php!你能告诉我我做错了什么吗?

1 个回复
SO网友:Jaed Mosharraf

您应该更正与slug匹配的主题文件夹上的文件名

例如:

single-services\\u cpt。php

希望您收到错误:)

结束

相关推荐

在Single.php中显示其他类别帖子

我的单曲。php我想显示当前帖子,在它下面我想列出cat-2中的所有帖子。在我的循环中,我试图用cat-2查询帖子,但它仍然显示当前帖子。<?php global $query_string; $posts = query_posts($query_string.\'\'); ?> <?php if (have_posts()): while (have_posts()) : the_post(); ?> <h4>