[英]Wordpress - custom archive page for post type from plugin
我创建了一个非常基本的插件,它添加了一个带有几个分类法和一些自定义字段的自定义帖子类型。 我宁愿使用插件而不是简单地将它添加到主题中,因为我认为我将来可能会有用。 问题是我想为特定的帖子类型自定义存档页面。 我显然可以创建一个新文件,在这种情况下是 archive-research.php,但是将它放在主题目录中会破坏使用插件的目的。 有没有一种方法可以让我将自定义存档文件作为插件本身的一部分?
使用archive_template
过滤器,来自 WordPress 代码: https : //codex.wordpress.org/Plugin_API/Filter_Reference/archive_template
<?php
function get_custom_post_type_template( $archive_template ) {
global $post;
if ( is_post_type_archive ( 'my_post_type' ) ) {
$archive_template = dirname( __FILE__ ) . '/post-type-template.php';
}
return $archive_template;
}
add_filter( 'archive_template', 'get_custom_post_type_template' ) ;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.