我正在处理一个木材/细枝模板,并创建了一个自定义的帖子类型,其分类法特定于该帖子类型。
$tour_labels = array(
\'name\' => _x( \'Tours\', \'Post Type General Name\', \'standrews\' ),
\'singular_name\' => _x( \'Tour\', \'Post Type Singular Name\', \'standrews\' ),
\'menu_name\' => __( \'Tours\', \'standrews\' )
);
$tour_rewrite = array(
\'slug\' => \'tours-excursion\',
\'with_front\' => false,
\'pages\' => true,
\'feeds\' => true,
);
$tour_args = array(
\'label\' => __( \'Tours\', \'standrews\' ),
\'description\' => __( \'Tour Description\', \'standrews\' ),
\'labels\' => $tour_labels,
\'supports\' => array( \'title\', \'excerpt\', \'thumbnail\', \'trackbacks\', \'revisions\', ),
\'taxonomies\' => array( \'post_tag\', \'tour_category\' ),
\'hierarchical\' => false,
\'has_archive\' => \'tours-excursions\',
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'rewrite\' => $tour_rewrite,
\'capability_type\' => \'post\',
);
register_post_type( \'tours\', $tour_args );
Taxomony创建旅游类别
$tours_labels = array(
\'name\' => _x( \'Categories Tours\', \'Taxonomy General Name\', \'standrews\' ),
\'singular_name\' => _x( \'Category Tour\', \'Taxonomy Singular Name\', \'standrews\' ),
\'menu_name\' => __( \'Categories Tours\', \'standrews\' )
);
$tours_rewrite = array(
\'slug\' => \'tours-excursions\',
\'with_front\' => true,
);
$tours_args = array(
\'labels\' => $tours_labels,
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'show_in_nav_menus\' => true,
\'show_tagcloud\' => true,
\'rewrite\' => $tours_rewrite,
);
register_taxonomy( \'tour_category\', array( \'tours\' ), $tours_args );
在tour\\u分类法中,我有3个类别(观光旅游、高尔夫休息和步行旅游)
我创建了一个旅游档案。php文件调用归档程序。细枝
$templates = array(\'archives/archive-tours.twig\');
$context = Timber::get_context();
$context[\'title\'] = \'Archive Tours\';
if (is_category()){
$context[\'title\'] = single_cat_title(\'\', false);
array_unshift($templates, \'archives/archive-\'.get_query_var(\'cat\').\'.twig\');
} else if (is_post_type_archive()){
$context[\'title\'] = post_type_archive_title(\'\', false);
array_unshift($templates, \'archives/archive-\'.get_post_type().\'.twig\');
}
$context[\'posts\'] = Timber::get_posts();
Timber::render($templates, $context);
Tours细枝模板
{% block content %}
<p>Archive (archive-tours.twig)</p>
{% for post in posts %}
{% include [\'teases/_tease-\'~post.post_type~\'.twig\', \'teases/tease.twig\'] %}
{% endfor %}
{% endblock %}
理想情况下,我的目标是为这三个类别调用一个单独的摘要模板,但不确定如何实现这一点。