我要投稿 | 网站地图 WordPress建站学习平台
WordPress教程网
热门标签: wordpress教程 wordpress函数 wordpress WordPress建站 wordpress插件

图文教程

当前位置:首页> 图文教程

WordPress函数get_template_part()

发布:WordPress教程网   发布时间: 2023-01-13  游览次数:45次

介绍

get_template_part( string $slug, string $name = null )

get_template_part()是用于调用主题目录中的文件。

参数

$slug
(string) (必填) The slug name for the generic template.

$name
(string) (选填) The name of the specialised template.

Default value: null

示例

调用主题中的 loop-index.php 文件。

<?php get_template_part( 'loop', 'index' ); ?>

调用子目录 partials 中的 content-page.php 文件。

<?php get_template_part( 'partials/content', 'page' ); ?>

调用不同的导航栏文件。

<?php get_template_part( 'nav' );           // Navigation bar (nav.php) ?>
<?php get_template_part( 'nav', '2' );      // Navigation bar #2 (nav-2.php) ?>
<?php get_template_part( 'nav', 'single' ); // Navigation bar to use in single pages (nav-single.php) ?>

本文版权归原作者所有,转载请注明原文来源出处, WordPress教程网 感谢您的支持!

本文链接: http://www.wpcn.net/712.html

WordPress教程网
WordPress教程网
相关内容