Wordpress中自定义帖子类型的自定义模板

Wordpress中自定义帖子类型的自定义模板,wordpress,wordpress-theming,custom-post-type,Wordpress,Wordpress Theming,Custom Post Type,我对Wordpress中自定义帖子类型的模板有问题。我已经尝试了很多方法,但是没有一种有效。。。我的帖子类型是post\u product,我的slug是produkty。我已经创建了single-post_product.php(以及许多其他变体),但它不起作用。这是我的代码: function post_product() { $args = array( 'label' => 'Produkty', 'public' => true,

我对Wordpress中自定义帖子类型的模板有问题。我已经尝试了很多方法,但是没有一种有效。。。我的帖子类型是post\u product,我的slug是produkty。我已经创建了single-post_product.php(以及许多其他变体),但它不起作用。这是我的代码:

function post_product() {
    $args = array(
      'label' => 'Produkty',
        'public' => true,
        'show_ui' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'archive' => false,
        'rewrite' => array('slug' => 'produkty'),
        'query_var' => true,
        'menu_icon' => 'dashicons-carrot',        
        'menu_position' => 5,
        'taxonomies'  => array( 'category' ),
        'supports' => array(
            'title',
            'editor',
            'excerpt',
            'trackbacks',
            'custom-fields',
            'revisions',
            'thumbnail',
            'author')
        );
    register_post_type( 'post_product', $args );
}
add_action( 'init', 'post_product' );

有人知道我做错了什么吗?

您需要创建名为single-produkty.php的文件


然后转到设置->永久链接并单击保存。现在应该可以了

您需要创建名为single-produkty.php的文件


然后转到设置->永久链接并单击保存。现在应该可以了

尝试在主题中创建
single produkty.php
,因为模板需要模板中的slug名称,因为这是用于重写规则的名称。添加模板,然后转到
Settings>Permalinks
并保存该页面,这将刷新重写规则,以防缓存中出现任何内容。

尝试在主题中创建
single produkty.php
,因为模板需要模板中的slug名称,因为这是用于重写规则的名称。添加模板,然后转到
设置>永久链接
并保存该页面,这将刷新重写规则,以防缓存中出现任何内容。

我写了一条评论,说它可以工作,但实际上不可以。。。我使用的函数显示了模板文件正在使用的内容,但它仍然使用single.php…再次尝试使用single-post_product.php并刷新永久链接,就像我在前面的回答中所说的那样。谢谢!这很有效。这很奇怪,因为我已经试过很多次了,而且第一次就成功了。我写评论说它成功了,但实际上没有。。。我使用的函数显示了模板文件正在使用的内容,但它仍然使用single.php…再次尝试使用single-post_product.php并刷新永久链接,就像我在前面的回答中所说的那样。谢谢!这很有效。这很奇怪,因为我已经试过很多次了,而且第一次就成功了。