我已使用Wordpress
和路由方法在Timber
内构建了自定义存档页面。页面运行良好,并显示Custom Post Types
的组合,但{url} / Feed的Feed不存在。
注意:以前的答案已被编辑,以消除令人困惑的副作用。
// create CPT (x 3)
register_post_type($name, array(
'label' => 'custom1',
'public' => true,
'capability_type' => 'page',
'supports' => array( 'title', 'author', 'excerpt', 'revisions', 'thumbnail'),
'taxonomies' => array('post_tag'),
'has_archive' => true
));
// CPT route
Routes::map('test/filter/:filter', function($params){
$query = array(
'post_type' => array('custom1', 'custom2', 'custom3' )
);
$filter = $params;
Routes::load('archive.php', $filter, $query, 200);
});
// paging CPT route
Routes::map('test/filter/:filter/page/:page', function($params){
$query = array(
'post_type' => array('custom1', 'custom2', 'custom3' ),
'paged' => intval($params['page'])
);
$filter = $params;
Routes::load('archive.php', $filter, $query, 200);
});
答案 0 :(得分:3)
add_action( 'pre_get_posts', function ( $query ) {
if ( $query->is_main_query() && !is_admin() && is_post_type_archive('agency')) {
$query->set( 'post_type', array('post', 'custom', 'custom2') );
}
} );
@sidonaldson - 这是一个未经考验的答案,但这里有什么可以尝试:
query_posts
基本上是WordPress等效的大锤,会影响RSS,分页和其他所有内容。这应该是什么......
$posts_query = array(
'post_type' => array('post', 'custom', 'custom' ),
'tag__in' => $tag_array,
'orderby' => 'date',
'post_status' => 'publish',
'paged' => $paged
);
// First let's get this set for pagination
query_posts($posts_query);
$context['posts'] = Timber::get_posts($posts_query);
$context['pagination'] = Timber::get_pagination();
// now let's use it to hit RSS
$post = new TimberPost('override_page_slug');
query_posts(array( 'p' => $post->ID ));
$context['post'] = $post;
Timber::render( 'page-override_page_slug.twig', $context );