【发布时间】:2018-12-09 02:43:12
【问题描述】:
所以在入门主题中我们有这个:
archive.php:
$templates = array( 'archive.twig', 'index.twig' );
$context = Timber::get_context();
$context['title'] = 'Archive';
if ( is_day() ) {
$context['title'] = 'Archive: ' . get_the_date( 'D M Y' );
} else if ( is_month() ) {
$context['title'] = 'Archive: ' . get_the_date( 'M Y' );
} else if ( is_year() ) {
$context['title'] = 'Archive: ' . get_the_date( 'Y' );
} else if ( is_tag() ) {
$context['title'] = single_tag_title( '', false );
} else if ( is_category() ) {
$context['title'] = single_cat_title( '', false );
array_unshift( $templates, 'archive-' . get_query_var( 'cat' ) . '.twig' );
} else if ( is_post_type_archive() ) {
$context['title'] = post_type_archive_title( '', false );
array_unshift( $templates, 'archive-' . get_post_type() . '.twig' );
}
$context['posts'] = new Timber\PostQuery();
Timber::render( $templates, $context );
据我了解,如果我导航到 http://.......com/index.php/category/newcategory/,它应该获取 archive-newcategory.twig 文件作为模板。 另一个例子,如果我去 http://.......com/index.php/category/anothercat/ 它应该去抓取 archive-anothercat.twig 。有可能我理解错了吗?因为如果是这种情况,我的入门主题将无法按预期工作。 如果不是这个,我在文档中找不到动态解决方案。
【问题讨论】:
标签: php wordpress twig categories timber