custom post types - How can I load Template file from wordpress plugin

I have created a plugin which displays testimonials and when each is clicked it redirects to the single page. So I wrote

I have created a plugin which displays testimonials and when each is clicked it redirects to the single page. So I wrote this code which is directing properly the single view to the one I created but only in that page its giving me an undefined get_header(); and get_footer()

//controller
class Jetty_Testimonials_Display_Single_Template{

  public function init(){

    //add_filter( 'template_include', array($this, 'jetty_get_template_hierarchy'));
    add_filter( 'template_include', array($this, 'jetty_template_chooser'), 99);

  }

  public function jetty_template_chooser( $template ) {

      $post_id = get_the_ID();

    if ( get_post_type( $post_id ) != 'jetty-testimonials' ) {
        return $template;
    }

    if ( is_single()  ) {
            return plugin_dir_url( __FILE__ ) . '../templates/single-jetty-testimonial.php';
    }

  }
<?php
/**
 *@uses output the single testimonial details
 * @package jetty-testimonials
 * @version 1.0.0
 */

get_header(); ?>
            <?php
            global $post_id;

            print_r($post_id);
            /* Start the Loop
            while ( have_posts() ) : the_post();

                get_template_part( 'template-parts/post/content', get_post_format() );

            endwhile; // End of the loop.*/
            ?>

<?php get_footer();?>

I have created a plugin which displays testimonials and when each is clicked it redirects to the single page. So I wrote this code which is directing properly the single view to the one I created but only in that page its giving me an undefined get_header(); and get_footer()

//controller
class Jetty_Testimonials_Display_Single_Template{

  public function init(){

    //add_filter( 'template_include', array($this, 'jetty_get_template_hierarchy'));
    add_filter( 'template_include', array($this, 'jetty_template_chooser'), 99);

  }

  public function jetty_template_chooser( $template ) {

      $post_id = get_the_ID();

    if ( get_post_type( $post_id ) != 'jetty-testimonials' ) {
        return $template;
    }

    if ( is_single()  ) {
            return plugin_dir_url( __FILE__ ) . '../templates/single-jetty-testimonial.php';
    }

  }
<?php
/**
 *@uses output the single testimonial details
 * @package jetty-testimonials
 * @version 1.0.0
 */

get_header(); ?>
            <?php
            global $post_id;

            print_r($post_id);
            /* Start the Loop
            while ( have_posts() ) : the_post();

                get_template_part( 'template-parts/post/content', get_post_format() );

            endwhile; // End of the loop.*/
            ?>

<?php get_footer();?>
Share Improve this question edited Jul 16, 2019 at 16:57 nmr 4,5672 gold badges17 silver badges25 bronze badges asked Nov 1, 2017 at 11:53 Leon TinasheLeon Tinashe 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

You can check below code : change Page slug "gym-dashboard" as per your requirement.

<?php
function rt_include_gym_dashboard_page_template( $template ) {
    if ( is_page( 'gym-dashboard' )  ) {
            return plugin_dir_path( __FILE__ ) . 'templates/content-gym-dashboard.php';
    }
    return $template;
}
add_filter( 'template_include', 'rt_include_gym_dashboard_page_template', 99 );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745317346a4622278.html

相关推荐

  • custom post types - How can I load Template file from wordpress plugin

    I have created a plugin which displays testimonials and when each is clicked it redirects to the single page. So I wrote

    10小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信