我没有这里的wordpress开发人员那么好,我希望有人能帮助我,我为酒店目的地创建了一个自定义的帖子类型,其中包含国家和城市的类别。当我去mysite的时候。POST正常显示的com/目的地。但当我试图通过访问mysite访问类别URL(例如,纽约)时。com/destinations/newyork我“找不到帖子”。
关于函数。php关于自定义post类型,我唯一能做的就是只调用自定义post类型php页面
require_once(\'hotels-manager.php\');
关于酒店经理。php,其中我实际创建了我拥有的自定义帖子类型:
<?php
if(!function_exists(\'hotel_manager_register\')){
function hotel_manager_register()
{
$labels = array(
\'name\' => __( \'Hotels Manager\' ),
\'singular_name\' => __( \'Hotel\' ),
\'add_new\' => __( \'Add New\' ),
\'add_new_item\' => __( \'Add New Hotel\' ),
\'edit_item\' => __( \'Edit Hotel\' ),
\'new_item\' => __( \'New Hotel\' ),
\'view_item\' => __( \'View Hotel\' ),
\'search_items\' => __( \'Search Hotel\' ),
\'not_found\' => __( \'No Hotel Found\' ),
\'not_found_in_trash\' => __( \'No Hotel Found In Trash\' ),
\'parent_item_colon\' => \'\',
\'menu_name\' => __( \'Hotels Manager\' )
);
$args = array(
\'labels\' => $labels,
\'menu_icon\' => \'dashicons-admin-multisite\',
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'destinations\', \'with_front\' => false),
\'capability_type\' => \'post\',
\'hierarchical\' => true,
\'menu_position\' => null,
\'has_archive\' => true,
\'supports\' => array( \'title\',\'editor\', \'thumbnail\', \'revisions\', \'custom-fields\')
);
register_post_type( \'destinations\', $args);
}
}
add_action(\'init\', \'hotel_manager_register\');
// hook into the init action and call create_book_taxonomies when it fires
add_action( \'init\', \'create_destinations_taxonomies\', 0 );
// create two taxonomies, genres and writers for the post type "book"
if(!function_exists(\'create_destinations_taxonomies\'))
{
function create_destinations_taxonomies() {
$labels = array(
\'name\' => __(\'Hotel Regions\'),
\'singular_name\' => __(\'Region\'),
\'search_items\' => __(\'Search Regions\'),
\'all_items\' => __(\'All Regions\'),
\'parent_item\' => __(\'Parent\'),
\'parent_item_colon\' => __(\'Parent:\'),
\'edit_item\' => __(\'Edit Region\'),
\'update_item\' => __(\'Update Region\'),
\'add_new_item\' => __(\'Add New Region\'),
\'new_item_name\' => __(\'New Region\'),
\'menu_name\' => __(\'Regions\'),
);
$args = array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'destinations\',\'with_front\' => false ),
);
register_taxonomy( \'destinations\', array( \'destinations\', \'public\' => true, ), $args );
}
}
?>
最后是索引。php只需调用:
<?php get_header(); ?>
<section class="stage">
<div class="container">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(\'Read More...\'); ?>
<?php endwhile; else: ?>
<p><?php _e(\'No posts were found. Sorry!\'); ?></p>
<?php endif; ?>
</div>
</section>
<?php get_footer(); ?>
任何帮助都将非常非常感谢。