Timber Custom Post Type Archive返回404分页

时间:2019-03-12 20:43:25

标签: php wordpress pagination twig timber

我正在使用Timber / Twig作为该网站。我有一个存档PHP文件,该文件呈现自定义帖子类型“ podcast”并创建分页,该页面显示在存档帖子页面上:

'localhost / podcasts /'

根据我设置的每页多少个帖子,它会产生设置的页面数量。例如总共10个帖子,每页3个帖子,呈现3个帖子,并且分4页。但是,链接“ / podcasts / page / 2”或更多会返回404。

如何获取带有下一组帖子的archive-template(“ podcast_cpt”)。twig?

我的Archive.php文件如下:


global $paged;
if (!isset($paged) || !$paged){
    $paged = 1;
}

$templates = array( 'archive.twig', 'index.twig' );

$context = Timber::get_context();

$podargs = array(
    // Get post type project
    'post_type' => 'sl_podcasts_cpts',
    'posts_per_page' => 3,
    'paged' => $paged,
    'page' => $paged,
    // Order by post date
    'orderby' => array(
        'date' => 'DESC'
    ));

$myCollection = new Timber\PostQuery( $podargs );
$context['podcasts'] = $myCollection;
$context['pagination'] = $myCollection->pagination();


$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, '/archives/archive-' . get_post_type() . '.twig' );
}

$context['posts'] = new Timber\PostQuery();

Timber::render( $templates, $context );

它呈现在树枝文件中:

{% for podcast in podcasts %}
     {% include 'partials/podcast-player.twig' %}
{% endfor %}
{% include 'pagination.twig' with {'posts': podcasts} %}

0 个答案:

没有答案