Php Wordpress自定义文章类型单页
我在WordPress中创建了一个名为eggs的自定义帖子类型,其CPT用户界面为 在名为eggs.php的文件中,我输入了以下代码:Php Wordpress自定义文章类型单页,php,wordpress,Php,Wordpress,我在WordPress中创建了一个名为eggs的自定义帖子类型,其CPT用户界面为 在名为eggs.php的文件中,我输入了以下代码: <?php $args = array('post_type' => 'eggs'); $query = new WP_Query($args); ?> <?php if ($query->have_posts() ) : while( $query->have_posts() ) : $query->the_post
<?php
$args = array('post_type' => 'eggs');
$query = new WP_Query($args);
?>
<?php if ($query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>
<a href="<?php the_permalink(); ?>" Go to Eggs Single Page</a>
<?php endwhile; endif; wp_reset_postdata(); ?>
现在我已经创建了一个名为single-eggs.php的文件,当我点击permalink时,它会在一个页面上重定向我,页面上会显示“对不起,没有帖子符合您的标准。”。它没有像我所希望的那样转到single-eggs.php页面
编辑:目前我正在使用WebDevStudios提供的自定义帖子类型UI插件。
当我使用OnTheGoSystems的Types插件时,它会找到single-template.php。该插件可能有问题吗?您不必使用插件注册自定义帖子类型,只需使用
注册帖子类型
功能注册您自己的CPT:
function my_cpt_eggs(){
$labels = array(
'name' => __( 'eggs' ),
'singular_name' => __( 'egg' ),
'menu_name' => __( 'eggs' ),
'all_items' => __( 'All eggs' ),
'add_new' => __( 'Add egg' ),
'add_new_item' => __( 'Add New egg' ),
'edit_item' => __( 'Edit egg' ),
'new_item' => __( 'New egg' ),
'view_item' => __( 'View egg' ),
'search_items' => __( 'Search eggs' ),
'not_found' => __( 'Not found' ),
'not_found_in_trash' => __( 'Not found in Trash' )
);
$args = array(
'label' => __( 'eggs' ),
'labels' => $labels,
'description' => __( 'egg items' ),
'public' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 10,
'capability_type' => 'post',
'map_meta_cap' => true,
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ),
'taxonomies' => array(),
'has_archive' => true,
'query_var' => true,
'can_export' => true,
);
}
add_action( 'init', 'my_cpt_eggs' );
将上述代码片段放入functions.php
文件中
之后,您可以创建您的single eggs.php
,一切都会好起来
请记住,您可能需要刷新重写规则。要做到这一点,你应该去
Wordpress Admin > Settings > Permalinks
只需点击底部的“强>保存设置< /强>按钮。
我使用另一个插件使之有效,但我会把你的答案看作是将来使用它的一个很好的解决方案。非常感谢你!