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

php - How to Include a Loop Template File in a Plugin

programmeradmin2浏览0评论

I am trying to include a template file into a loop i made in a shortcode, in a plugin. Everything shows up fine when the template is actually pasted into the loop, but to make things neat I want to separate it into it's own file.

I created a file called hi.php and it's located in a plugin subfolder called parts.

Here is the code I place in the loop, but it is not loading the template:

include plugins_url( '/parts/hi.php', __FILE__ );

I am trying to include a template file into a loop i made in a shortcode, in a plugin. Everything shows up fine when the template is actually pasted into the loop, but to make things neat I want to separate it into it's own file.

I created a file called hi.php and it's located in a plugin subfolder called parts.

Here is the code I place in the loop, but it is not loading the template:

include plugins_url( '/parts/hi.php', __FILE__ );

Share Improve this question edited Aug 7, 2019 at 17:09 Edegist asked Aug 7, 2019 at 16:54 EdegistEdegist 1331 silver badge10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

I do it like this:

// Inclusion of additional php files
define( 'MYPLUG_DIR', plugin_dir_path( __FILE__ ) );

require_once( MYPLUG_DIR . 'hi.php' );

It lets you use that more easily if you have to include several files.

发布评论

评论列表(0)

  1. 暂无评论