4

所以我在一个 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_memberswww.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();
?>
4

1 回答 1

12

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

于 2013-01-22T19:26:47.447 回答