最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to include a page template and template part into my plugin

programmeradmin0浏览0评论

I am creating my first plugin with a template for the frontend.

My current structure is:

/my_plugin/views/page_templates

I have 2 main issues I am trying to resolve

  1. Is this the best way to include a template
  2. How to include external files into template using get_template_part()

The template code:

function mbbp_frontend_page_layout($page_template) {
    global $post;
    
    if ( is_page("bookings") ) {
        
        $page_template = MBBP_BOOKING_PLUGIN_DIR_PATH . '/views/page-bookings.php';
        
    }
    return $page_template;
}
add_filter("page_template", "mbbp_frontend_page_layout");

And then, within page-bookings.php I have included:

<?php get_template_part( 'page-templates', 'payment-form' ); ?>

The get_template_part() code is not including anything so I am assuming it is because of the way my template is included in the plugin but as this my first plugin, I do not know how to better handle this.

发布评论

评论列表(0)

  1. 暂无评论