我正在编写一个插件,它将显示历史事件的时间线,我正在寻找使输出可定制的方法。我正在考虑在插件文件夹中包含一个模板/示例,可以在主题文件夹中覆盖该模板/示例。我的想法是确保WP在使用我创建的模板之前,先在主题文件夹中查找自定义模板。
如果这不是好的做法,请告诉我!
我可以使用哪些功能来实现上述功能?
我正在编写一个插件,它将显示历史事件的时间线,我正在寻找使输出可定制的方法。我正在考虑在插件文件夹中包含一个模板/示例,可以在主题文件夹中覆盖该模板/示例。我的想法是确保WP在使用我创建的模板之前,先在主题文件夹中查找自定义模板。
如果这不是好的做法,请告诉我!
我可以使用哪些功能来实现上述功能?
/**
* The shortcode [history_timeline] with a custom output template.
*/
add_shortcode( \'history_timeline\', function( $atts = array(), $content = \'\' )
{
ob_start();
if ( \'\' == locate_template( \'templates/timeline.php\', TRUE ) )
include( plugin_dir_path( __FILE__ ) . \'templates/timeline.php\' );
$html = ob_get_clean();
return $html;
});
其中短代码是[history_timeline]
和if ( \'\' == locate_template( \'templates/timeline.php\', TRUE ) )
include( plugin_dir_path( __FILE__ ) . \'templates/timeline.php\' );
指:如果/wp-content/themes/MYTHEME/templates/timeline.php
,则将自动加载。
其他:/wp-content/plugins/history-timeline/templates/timeline.php
已加载。
我们假设__FILE__
在history-timeline
根目录。
我已经注册了一个名为“Services”的自定义帖子类型,但当我给这篇帖子提供模板“single Services.php”时,它不接受这个,而是选择了“homepage.php”模板,你能告诉我这个问题吗?它也没有使用“archive services.php”模板,而是使用blog模板(index.php)使现代化代码如下:add_action(\'init\', \'services_register\'); function services_register() { $