向云端 發表於 2023-6-22 00:00:00

WordPress主题制作之模板文件的引入方法

<p>
get_template_part() 用来引用模板文件,类似于 get_header()、get_sidebar() 和 get_footer(),只不过这个 get_template_part() 可以引入自定义名字的文件。</p>
<p>
使用方法</p>
<div>
<div>
<div id="highlighter_453815">
<div>
<span>?</span>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>get_template_part( </code><code>$slug</code><code>, </code><code>$name</code> <code>);</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
参数</p>
<p>
$slug</p>
<p>
(字符串)(必须)要引入的模板的文件名,不包括后缀名 .php,也就是如果需要引入当前主题根目录的 loop.php 文件 $slug 填写 “loop” 即可。</p>
<p>
默认:None</p>
<p>
$name</p>
<p>
(字符串)(可选)要引入的模板的文件的副文件名,如果要引入当前主题根目录的 loop-img.php 文件 $slug 参数填写 “loop”,$name 参数填写 “img”。</p>
<p>
默认值:None</p>
<p>
返回值</p>
<p>
此函数无返回值。</p>
<p>
例子</p>
<p>
引入当前主题根目录的 endskin.com 文件:</p>
<div>
<div>
<div id="highlighter_67880">
<div>
<span>?</span>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>get_template_part( </code><code>'endskin'</code> <code>);</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
引入当前主题 part 目录的 loop.php 文件:</p>
<div>
<div>
<div id="highlighter_651523">
<div>
<span>?</span>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>get_template_part( </code><code>'part/loop'</code> <code>);</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
引入当前主题根目录的 endskin-com.php 文件:</p>
<div>
<div>
<div id="highlighter_960598">
<div>
<span>?</span>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>get_template_part( </code><code>'endskin'</code><code>, </code><code>'com'</code> <code>);</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
其它</p>
<p>
此函数位于:wp-includes/general-template.php</p>
頁: [1]
查看完整版本: WordPress主题制作之模板文件的引入方法