自定义发布类型缺少发布属性部分

时间:2019-07-20 作者:Alt C

这就是我创建自定义帖子类型的方式

function wp_custom_post_type_listing()
{

    $labels = array(
        \'name\'               => _x(\'Listing\', \'post type general name\', \'wpprolister\'),
        \'singular_name\'      => _x(\'Listing\', \'post type singular name\' ,\'wpprolister\'),
        \'add_new\'            => _x(\'Add new listing\', \'l\', \'wpprolister\'),
        \'all_item\'           => __(\'All Listing\', \'wpprolister\'),
        \'add_new_item\'       => __(\'Add new listing\', \'wpprolister\'),
        \'edit_item\'          => __(\'Edit Listing\', \'wpprolister\'),
        \'new_item\'           => __(\'New Listing\', \'wpprolister\'),
        \'view_item\'          => __(\'View Listing\', \'wpprolister\'),
        \'search_item\'        => __(\'Search Listing\', \'wpprolister\'),
        \'not_found\'          => __(\'No Listing found\', \'wpprolister\'),
        \'not_found_in_trash\' => __(\'No listings found in trash\', \'wpprolister\'),
        \'parent_item_colon\'  => __(\'Parent Listing\', \'wpprolister\'),
    );

    $args_listing = array(
        \'labels\'              => $labels,
        \'public\'              => true,
        \'has_archive\'         => true,
        \'publicly_queryable\'  => true,
        \'query_var\'           => true,
        \'rewrite\'             => true,
        \'menu_icon\'           => plugins_url( \'images/list.png\', __FILE__ ),
        \'capability_type\'     => \'listing\',
        \'capabilities\'        => array(
            \'edit_post\'              => \'edit_listing\',
            \'read_post\'              => \'read_listing\',
            \'delete_post\'            => \'delete_listing\',
            \'edit_posts\'             => \'edit_listings\',
            \'edit_others_posts\'      => \'edit_others_listings\',
            \'publish_posts\'          => \'publish_listings\',
            \'read_private_posts\'     => \'read_private_listings\',
            \'create_posts\'           => \'edit_listings\',
            \'delete_posts\'           => \'delete_listings\',
            \'delete_published_posts\' => \'delete_published_listing\',
            \'delete_others_posts\'    => \'delete_others_listings\',
            \'edit_published_posts\'   => \'edit_published_listings\',
        ),
        \'hierarchical\'        => false,
        \'map_meta_cap\'        => false,
        \'supports\'            => array(
            \'title\',
            \'editor\',
            \'expert\',
            \'thumbnail\',
            \'comments\',
            \'page-attributes\',
        ),
        \'taxonomies\'          => array(\'listing_categories\', \'locations\', \'amenities\', \'post_tag\'),
        \'menu_position\'       => 2,
        \'exclude_from_search\' => false,
    );
    register_post_type(\'l\', $args_listing);
}
但用于选择帖子模板的帖子属性不会显示。我在模板中添加了page-fullwidth.php

<?php if ( ! defined( \'ABSPATH\' ) ) exit;
/*
Template Name: Full Width
Template Post Type: post, page , l
*/
get_header();
get_template_part( \'/wpprolister-templates/content\', \'titlebar\'); ?>
我已经为自定义帖子类型分配了模板single-l.php 但我想要一个额外的帖子模板

1 个回复
SO网友:Faham Shaikh

如果我正确理解了您的问题,您需要在自定义帖子类型中选择页面模板的选项。为了做到这一点,你必须采取不同的方法。

在您的page-fullwidth.php 使用以下代码添加模板名称:

/*
Template Name: Full-width layout
Template Post Type: l
*/
get_header();
理论上,默认模板应该回退到single-l.php 如果没有,请告诉我。

也为了消除误解page_attributes 参数,它仅提供选择菜单顺序和选择父项的选项,如果hierarchical 设置为true。

相关推荐

Custom term templates

所以,我在网上做了一些研究,但没有找到可靠的答案,所以我来了。我需要为特定类别创建自定义woocommerce类别页面。例如,我有一个类别叫做“Awesome”。而不是使用由短代码生成的常规类别页面[product_category category=\"something\"], 我想为自定义特定类别页面Awesome.我发现我需要编辑taxonomy-product_cat.php 但我不知道如何将其链接到名为awesome.换句话说,我正在考虑制作php文件的自定义副本,然后将其添加为主题templ