什么会使自定义帖子类型模板不显示?

时间:2013-01-22 14:49:18

标签: wordpress custom-post-type

所以我正在使用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
 ));    

}

然后我创建了一个single-staff_members.php文件,其中包含WordPress循环,但是当我导航到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();
?>

1 个答案:

答案 0 :(得分:11)

刷新永久链接结构(设置 - &gt;永久链接点击保存)。