我想在普通页面模板中显示我插件的自定义帖子类型存档。我的方法是:
function my_include_template($template) {
global $post;
if ( is_post_type_archive(\'my_custom_post\') ) {
$new_template = locate_template( array( \'page.php\' ) );
if ( \'\' != $new_template ) {
return $new_template ;
}
}
return $template;
}
add_filter(\'template_include\', \'my_include_template\', 99);
这样可以打开页面。php模板将被获取,但模板本身的get\\u template\\u part()函数将为存档中的每个帖子调用。但事实上,我不想这样做,我只是想通过使用普通页面模板输出此存档中所有帖子的列表:例如:。
第1篇第2篇第3篇
<?php get_header(); ?>
<div class="my-content">
...
</div>
<?php get_footer(); ?>
因为像上面这样的自定义模板文件,如果主题具有非标准结构,可能会破坏布局。因此,这就是为什么最好在主题本身的普通页面模板中输出我的存档文件的原因。
有什么建议如何处理这个问题吗?
更新1我必须指定:当然我可以替换用户选择的内容;“我的档案”;页到目前为止,这将适用于常规自定义后期归档。
我的问题是,我还有一个分类法作为帖子的类别。所以我的鼻涕虫看起来像:
单帖:/article/postname/CPT归档:/articles/类别分类:/articles/category1/可以对两个归档使用相同的页面,但当然,在访问/articles/category1/时,只应显示该类别的帖子,并保留url。所以我不能简单地重定向到/文章/页面。