我使用以下代码创建了一个自定义帖子类型:
add_action(\'init\', \'create_trans_career\');
function create_trans_career() {
//Arguments to create post type.
$args = array(
\'labels\' => array(
\'name\' => __(\'Career\', \'trans\'),
\'singular_name\' => __(\'Career\', \'trans\'),
\'add_new\' => __(\'Add New\', \'trans\'),
\'add_new_item\' => __(\'Add New Career Item\', \'trans\'),
\'edit\' => __(\'Edit\', \'trans\'),
\'edit_item\' => __(\'Edit Career Item\', \'trans\'),
\'new_item\' => __(\'New Career\', \'trans\'),
\'view\' => __(\'View\', \'trans\'),
\'view_item\' => __(\'View Career\', \'trans\'),
\'search_items\' => __(\'Search Career\', \'trans\'),
\'not_found\' => __(\'No Career item found\', \'trans\'),
\'not_found_in_trash\' => __(\'No Career item found in Trash\', \'trans\'),
),
\'public\' => true,
\'show_ui\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => true,
\'has_archive\' => true,
\'menu_icon\' => get_bloginfo(\'template_directory\'). \'/images/career-icon.png\',
\'supports\' => array(\'title\', \'editor\', \'thumbnail\'),
\'rewrite\' => array(\'slug\' => \'career\', \'with_front\' => false),
);
//Register type and custom taxonomy for type.
register_post_type( \'career\' , $args );
}
我还创建了一个页面(single career.php):
<?php while ( have_posts() ) : the_post(); ?>
<h2 class="page-title"><?php the_title(); ?></h2>
<hr />
<?php the_content(\'Read More...\'); ?>
<a href="<?php bloginfo(\'wpurl\'); ?>/career" title="<?php _e(\'Back to jobs listings\', \'trans\'); ?>" class="back-to-jobs"><?php _e(\'Back to jobs listings\', \'trans\'); ?></a>
<?php endwhile; ?>
。。以及用于列出帖子的页面模板:
$mypost = array( \'post_type\' => \'career\', \'posts_per_page\' => 10, \'paged\' => $pagedNum );
$loop = new WP_Query( $mypost ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post();?>
<tr id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<td><?php the_title(); ?></td>
<td><?php echo $location; ?></td>
<td><?php echo $close_date; ?></td>
<td><a href="<?php the_permalink(); ?>" title="<?php _e(\'Details\', \'trans\'); ?>"><?php _e(\'> Details\', \'trans\'); ?></a></td>
<td class="apply-now"><a data-title="<?php the_title(); ?>" data-location="<?php echo $location; ?>" href="#apply_<?php the_ID(); ?>" title="<?php _e(\'Apply Now\', \'trans\'); ?>" class="career-apply"><?php _e(\'Apply Now\', \'trans\'); ?></a></td>
</tr>
<?php endwhile; ?>
我使用上面的模板创建了一个包含作业的页面。。我看到了所有的帖子。。但当我打开一个页面时,我收到404错误。问题出在哪里?