我有一个自定义的帖子类型设置(实际上有两个)没有正确显示。我希望这两种帖子的问题是一样的。
这是我的一种帖子类型(公文包)的代码。第二个非常相似。
<?php
add_action(\'init\', \'ccd_portfolio\');
function ccd_portfolio() {
$labels = array(
\'name\' => _x(\'Portfolio\', \'post type general name\'),
\'singular_name\' => _x(\'Project\', \'post type singular name\'),
\'add_new\' => _x(\'Add New\', \'ccd_portfolio item\'),
\'add_new_item\' => __(\'Add New Project\'),
\'edit_item\' => __(\'Edit Project\'),
\'new_item\' => __(\'New Project\'),
\'view_item\' => __(\'View Project\'),
\'search_items\' => __(\'Search Projects\'),
\'not_found\' => __(\'Nothing found\'),
\'not_found_in_trash\' => __(\'Nothing found in Trash\'),
\'parent_item_colon\' => \'\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'query_var\' => true,
\'menu_icon\' => get_stylesheet_directory_uri() . \'/images/icons/plugins/portfolio.png\',
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'menu_position\' => null,
\'supports\' => array(\'title\', \'editor\', \'excerpt\', \'author\'),
\'can_export\' => true,
\'show_in_menu\' => true,
\'has_archive\' => true,
\'rewrite\' => array(\'slug\' => \'work\')
);
register_post_type( \'portfolio\' , $args );
flush_rewrite_rules();
}
add_action("admin_init", "ccdport_admin_init");
function ccdport_admin_init(){
add_meta_box("mb_ccdport_details", "Project Details", "ccdport_details", "portfolio", "normal", "high");
add_meta_box("mb_ccdport_client", "Client", "ccdport_client", "portfolio", "side", "high");
}
add_action( \'admin_enqueue_scripts\', \'ccdport_add_datepicker\' );
function ccdport_add_datepicker(){
wp_enqueue_script( \'jquery-ui-datepicker\' );
wp_enqueue_style(\'jquery-datepicker-style\', \'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css\');
}
function ccdport_details(){
global $post;
$custom = get_post_custom($post->ID);
$preview_url = $custom[\'preview_url\'][0];
$start_date = $custom[\'start_date\'][0];
$end_date = $custom[\'end_date\'][0];
?>
<p><label>Preview URL: <strong>http://</strong>
<input type="text" size="35" name="preview_url" value="<?php echo $preview_url; ?>" /></p>
<p><label>Start date:</label>
<input id="startDate" type="text" size="15" class="DatePicker" name="start_date" value="<?php echo $start_date; ?>" />
<label>End date:</label>
<input id="endDate" type="text" size="15" class="DatePicker" name="end_date" value="<?php echo $end_date; ?>" /></p>
<script>
jQuery(document).ready(function() {
jQuery(\'input.DatePicker\').datepicker({
dateFormat : \'dd-mm-yyyy\'
});
});
</script>
<?php
}
function ccdport_client(){
global $post;
$custom = get_post_custom($post->ID);
$client = $custom[\'project_client\'][0];
$name = $custom[\'client_name\'][0];
$args = array(
\'post_type\' => \'clients\',
\'posts_per_page\' => -1,
\'orderby\' => \'name\',
\'order\' => \'ASC\'
);
?>
<p><label>Client name</label></p>
<input type="text" name="client_name" value="<?php echo $name; ?>" />
<p><label>Organisation</label></p>
<?php
$query = new WP_Query( $args );
if ( $query->have_posts() ){
echo \'<select name="project_client">\';
while ( $query->have_posts() ){
$query->the_post();
$slug = $post->post_name;
echo \'<option value="\'.$slug.\'" \'.selected($slug, $client).\'>\'.get_the_title().\' (\'.$slug.\')</option>\';
}
echo \'</select>\';
}
else { echo \'<p>There are currently no clients registered</p>\'; }
}
add_action(\'save_post\', \'ccdport_save_details\');
function ccdport_save_details(){
global $post;
update_post_meta($post->ID, "client_name", $_POST["client_name"]);
update_post_meta($post->ID, "project_client", $_POST["project_client"]);
update_post_meta($post->ID, "portfolio", $_POST["portfolio"]);
update_post_meta($post->ID, "preview_url", $_POST["preview_url"]);
}
?>
每个帖子类型都包含在一个单独的文件中,并被调用到函数中。带有include命令的php。这些文件完美地显示在管理区域,帖子被完美地保存,等等。但是,主题文件(archive-portfolio.php和single-portfolio.php)没有加载。相反,将显示我的自定义主页。
我不知道会是什么问题。我已经用每种帖子类型刷新了重写规则,删除它也没有任何作用。我最近才开始使用自定义帖子类型,所以任何帮助都会非常有用。我已经看过了其他答案,但它们似乎对我的情况没有帮助。我试着重新保存我的永久链接,但没有用。我试过换衣服\'has_archive\' => true
到\'has_archive\' => \'portfolio\'
, 没有什么我错过了什么吗?很可能是显而易见的事情?