我无法正确注册自定义帖子类型。它似乎正在识别为页面帖子类型并使用该模板。我也无法访问它的存档页。知道怎么了吗?
add_action( \'init\', \'register_cpt_women\' );
function register_cpt_women() {
$womenLabels = array(
\'name\' => _x( \'The Women\', \'women\' ),
\'singular_name\' => _x( \'The Women\', \'women\' ),
\'add_new\' => _x( \'Add New\', \'women\' ),
\'add_new_item\' => _x( \'Add New Woman\', \'women\' ),
\'edit_item\' => _x( \'Edit Woman\', \'women\' ),
\'new_item\' => _x( \'New Woman\', \'women\' ),
\'view_item\' => _x( \'View Woman\', \'women\' ),
\'search_items\' => _x( \'Search Women\', \'women\' ),
\'not_found\' => _x( \'No women found\', \'women\' ),
\'not_found_in_trash\' => _x( \'No women found in Trash\', \'women\' ),
\'parent_item_colon\' => _x( \'Parent Woman:\', \'women\' ),
\'menu_name\' => _x( \'The Women\', \'women\' ),
);
$womenArgs = array(
\'labels\' => $womenLabels,
\'hierarchical\' => false,
\'description\' => \'The Women Listing\',
\'supports\' => array( \'title\', \'editor\', \'thumbnail\' ),
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 6,
\'menu_icon\' => \'/wp-content/themes/ssekoDesigns/assets/img/ico-jobs.png\',
\'show_in_nav_menus\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => false,
\'has_archive\' => true,
\'query_var\' => true,
\'can_export\' => true,
\'rewrite\' => true,
\'capability_type\' => \'post\'
);
register_post_type( \'women\', $womenArgs );
}
SO网友:Iftieaq
Use this code
<?php
/* Testimonial */
function dyn_testimonial_post_tipe() {
register_post_type( \'testimonial\',
array(
\'label\' => __(\'Testimonial\'),
\'singular_label\' => __(\'testimonial Name\'),
\'_builtin\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_nav_menus\' => true,
\'hierarchical\' => true,
\'capability_type\' => \'page\',
\'menu_icon\' => get_template_directory_uri() . \'/lib/post-tipe/icon/testimonial.png\',
\'rewrite\' => array(
\'slug\' => \'testimonial-view\',
\'with_front\' => FALSE,
),
\'supports\' => array(
\'title\',
\'editor\',
\'thumbnail\')
)
);
register_taxonomy(\'testimonial_category\', \'testimonial\',
array(
\'hierarchical\' => true,
\'label\' => \'Testimonial Categories\',
\'singular_name\' => \'Category\',
"rewrite" => true,
"query_var" => true));
}
add_action(\'init\', \'dyn_testimonial_post_tipe\');
// Add to admin_init function
add_action(\'manage_testimonial_posts_custom_column\' , \'custom_testimonial_columns\', 10, 2);
add_filter(\'manage_edit-testimonial_columns\', \'my_testimonial_columns\');
//Add columns for Testimonial posts
function my_testimonial_columns($columns) {
$columns = array(
"cb" => "<input type=\\"checkbox\\" />",
"title" => "Title",
"testimonial_categories" => "Categories",
"comments" => "<span><span class=\\"vers\\"><img src=\\"".get_admin_url()."images/comment-grey-bubble.png\\" alt=\\"Comments\\"></span></span>",
"date" => "Date",
);
return $columns;
}
function custom_testimonial_columns( $column, $post_id ) {
switch ( $column ) {
case \'testimonial_categories\':
$terms = get_the_term_list( $post_id , \'testimonial_category\' , \'\' , \',\' , \'\' );
if ( is_string( $terms ) ) {
echo $terms;
} else {
echo \'Uncategorized\';
}
break;
}
}
?>