WordPress single-{cpt}.php不工作
这是我必须生成自定义帖子类型的php:WordPress single-{cpt}.php不工作,php,wordpress,custom-post-type,Php,Wordpress,Custom Post Type,这是我必须生成自定义帖子类型的php: function custom_post_type() { $args = array( 'label' => __( 'Products', 'rgo' ), 'labels' => $labels, 'supports' => array( 'title', 'custom-fields', ),
function custom_post_type() {
$args = array(
'label' => __( 'Products', 'rgo' ),
'labels' => $labels,
'supports' => array( 'title', 'custom-fields', ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 20,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'rgo-products', $args );
}
add_action( 'init', 'custom_post_type', 1 );
然后我有一个名为single rgo products.php
的文件来处理单个帖子,但是在查看CPT单个页面时不会加载该文件。我甚至不确定加载的是什么模板。我尝试了对single.php
和index.php
文件进行更改,以查看是否进行了更改,但没有
我尝试过通过进入设置>永久链接更新永久链接,并保存了几次。刷新永久链接设置并重新加载自定义单页。我希望它能工作。刷新永久链接设置并重新加载自定义单页。我希望它能工作。自定义单页的名称是错误的。名称应为single+(自定义帖子类型)自定义单个页面的名称错误。Name should single+(自定义帖子类型)您是否在编辑问题时错误地删除了
$labels
变量,或者您忘记了设置它?我删除了代码中的$labels部分,以便在这里发布时使其变小,因为我非常确定它与问题无关。如果你认为这与此有关,我可以发布@cabrerahectorHey@akschoeck,刚刚复制并粘贴了您的代码(并将$labels
数组添加到了216th的functions.php中),创建了一个名为single rgo products.php的文件,刷新了permalinks,一切都按预期进行了:WordPress为我加载了正确的模板。尝试切换到另一个主题并重复我所做的操作,以查看它是否有效。您是否在编辑问题时错误地删除了$labels
变量,或者您忘记了设置它?我删除了代码中的$labels部分,以便在此处发布时使其变小,并且因为我非常确定它与问题无关。如果你认为这与此有关,我可以发布@cabrerahectorHey@akschoeck,刚刚复制并粘贴了您的代码(并将$labels
数组添加到了216th的functions.php中),创建了一个名为single rgo products.php的文件,刷新了permalinks,一切都按预期进行了:WordPress为我加载了正确的模板。试着切换到另一个主题,重复我所做的,看看它是否有效。