我使用以下代码创建了一个主题CPT
function pp_themes_post_type() {
$args = array(
\'public\' => true,
\'label\' => \'ProfilePress Themes\',
\'has_archive\' => true,
\'hierarchical\' => true,
\'supports\' => array( \'title\', \'editor\', \'page-attributes\', \'revisions\', \'thumbnail\' ),
\'taxonomies\' => array( \'category\', \'post_tag\' )
);
register_post_type( \'themes\', $args );
}
add_action( \'init\', \'pp_themes_post_type\' );
然后我创建了
archive-themes.php
包含以下代码的模板文件,该代码显示分类为主题的Easy digital downloads产品。
$paged = get_query_var( \'paged\', 1 );
$args = array(
\'post_type\' => \'download\',
\'offset\' => 0,
\'paged\' => $paged,
\'posts_per_page\' => $posts_per_page,
\'tax_query\' => array(
array(
\'taxonomy\' => \'download_category\',
\'field\' => \'slug\',
\'terms\' => \'theme\' //if field is ID you can reference by cat/term number
)
),
);
$wp_query = new WP_Query( $args );
查看主题CPT输出分类为主题的edd产品(请参阅
http://profilepress.net/themes/)
当你试图转到下一页404时,问题就出现了。(参见http://profilepress.net/themes/page/2 )我已安装What Template File Am I Viewing? 插件并发现archive-themes.php
查看第2页时未使用模板。
我需要尽我所能的帮助。
SO网友:Pmpr
无需像这样处理分页:
$paged = get_query_var( \'paged\', 1 );
只需将此放在循环之后:
get_the_posts_pagination(
\'mid_size\' => 1,
\'prev_text\' => \' \',
\'next_text\' => \' \',
\'screen_reader_text\' => \'A\'
)
像这样:
if( have_posts() ){
while( have_posts() ){
the_post();?>
the_content();?>
<?php }
echo get_the_posts_pagination(
\'mid_size\' => 1,
\'prev_text\' => \' \',
\'next_text\' => \' \',
\'screen_reader_text\' => \'A\'
);
wp_reset_postdata();
}?>