深入解析WordPress中加载模板的get_template_part函数
(编辑:jimmy 日期: 2025/7/5 浏览:3 次 )
最近研究官方主题 Twenty Eleven ,有一些东西网上现成的中文资料不好找,在博客里记载下来,算是分享,也算是备忘,wordpress 3.0 以后就开始便有了get_template_part() 这个函数 ,应该是为文章呈现形式提供更为多样化的选择而给出的新功能。
Twenty Eleven 中 实例如下:
Twenty Eleven index.php 文件
行:21
<"htmlcode"><"htmlcode">上一篇:WordPress中重置文章循环的rewind_posts()函数讲解<"htmlcode"><"htmlcode">function get_template_part( $slug, $name = null ) { //$tag = "get_template_part_{$slug}" //也就是,get_template_part_+你当时设置的$slug值 do_action( "get_template_part_{$slug}", $slug, $name ); $templates = array(); if ( isset($name) ) $templates[] = "{$slug}-{$name}.php"; $templates[] = "{$slug}.php"; locate_template($templates, true, false); }实例
像上面那样说,可能也许基本上有点看不明白,好吧给点实例
//复习一下get_template_part($slug, $name)的用法, //如果你在主题里这样 get_template_part( 'index' , 'photo'); //那么 WP 会去找主题根目录下 index-photo.php 文件 //那么我们想挂一个函数的话就得像如下 function addFunction ($slug, $name){ echo $slug; } add_action("get_template_part_index","addFunction",10,2);get_template_part() 函数详解备忘
下一篇:PHP实现基于文本的摩斯电码生成器
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。