我正在努力为各大城市的餐馆写一页。
我的第一页显示城市,单击任何城市,我将显示所有餐厅,单击单个餐厅,我将显示其详细信息。我的页面结构是什么。
home (home page)
--restaurant (layout/template-restaurant.php)
----Eastern Cape (taxonomy-province.php)
------KFC (single-restaurant.php)
我做得对吗?
我使用的是sanha restau模板。php作为页面模板。分类省。php显示有餐馆的省份。现在我很困惑,我应该遵循什么层次来显示单个省份的所有餐厅?
add_action( \'init\', \'restau\' );
function restau(){
register_post_type( \'sanha-restau\',
array(
\'labels\' => array(
\'name\' => __( \'Restaurants\' ),
\'singular_name\' => __( \'Restaurant\' )
),
\'public\' => true,
\'has_archive\' => true,
\'menu_icon\' => \'dashicons-media-text\',
\'hierarchical\' => true,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array(\'slug\' => \'restaurants\',),
\'supports\'=> array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\',),
)
);
}
add_action( \'init\', \'create_restau_taxonomy\' );
function create_restau_taxonomy() {
register_taxonomy(
\'province\',
\'sanha-restau\',
array(
\'label\' => \'Province\',
\'hierarchical\' => true,
)
);
}
善意的建议
模板餐厅的代码。php
/*
Template Name: Restaurants Template
The template for displaying show image in header.
*/
get_header();
$custom_terms = get_terms(\'province\');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array(
\'post_type\' => \'sanha-restau\',
\'orderby\' => \'title menu_order\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'province\',
\'field\' => \'slug\',
\'terms\' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo \'<div">\';
echo \'<a href="\' . esc_url( get_term_link( $custom_term, $custom_term->taxonomy ) ) . \'">\'. $custom_term->name . \'</a><br>\';
echo \'</div>\';
}
}
get_footer();