所以我在一个 WordPress 网站上工作,我需要创建一个自定义帖子类型。我有使用 WordPress 初始化它的功能设置
add_action( 'init', 'init_staff' );
function init_staff(){
register_post_type('staff_members',array(
"labels" => array(
"name" => "Staff Members",
"singular_name" => "Staff Member",
"menu_name" => "Staff Members",
"add_new" => "Add New",
"add_new_item" => "Add New Staff Member",
"edit" => "Edit",
"edit_item" => "Edit Staff Member",
"new_item" => "New Staff Member",
"view" => "View",
"view_item" => "View Staff Member",
"search_items" => "Search Staff Members",
"not_found" => "No Staff Member Found",
"not_found_in_trash" => "Staff Member Not Found in Trash"
),
"public" => true,
"supports" => array('title','editor','thumbnail'),
"has_archive" => true
));
}
然后,我创建了一个包含 WordPress 循环的 single-staff_members.php 文件,但是当我导航到www.mysite.com/staff_members或www.mysite.com/staff_members/post_title时,我得到了您正在寻找的页面不存在404。
这是 single-staff_members.php 文件
<?php
get_header();
?>
<div id="leftcolumn">
<div class="main-content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts found.<p></p>
<?php endif; ?>
</div>
</div>
<?php
get_footer();
?>