舉例:獲取主題目錄下的文件,比如圖片文件
<?php
$dir = get_template_directory_uri();
?>
<a class="item"><img src="<?php echo $dir . '/assets/owl2/img/fullimage1.jpg'; ?>" alt=""></a>
url(<?php echo get_template_directory_uri(); ?>/assets/images/banner02.jpg)
背景圖片
<?php
$dir = get_template_directory_uri();
?>
<li role="complementary" id="banner-li" style="background-image: url(<?php echo $dir . '/assets/images/banner01.jpg'; ?>)">
//或者
<li role="complementary" id="banner-li" style="background-image: url(<?php echo get_template_directory_uri(); ?>/assets/images/banner02.jpg)">
舉例:
if ( 'posts' == get_option( 'show_on_front' ) ) {
include( get_home_template() );
}
原文:get_home_template
Retrieve path of home template in current or parent template.
獲取首頁模板的路徑
返回:首頁模板文件的全路徑,比如:
get_home_template():得到的路徑如下(如果沒有有home.php,會獲取index.php。)
E:\phpStudy\PHPTutorial\WWW\bootstrap4wp/wp-content/themes/wp-bootstrap-4-pro-child-theme/home.php
1
其他
get_front_page_template()
get_index_template()
get_page_template()
E:\phpStudy\PHPTutorial\WWW\bootstrap4wp/wp-content/themes/wp-bootstrap-4-pro-child-theme/front-page.php
E:\phpStudy\PHPTutorial\WWW\bootstrap4wp/wp-content/themes/wp-bootstrap-4-pro-child-theme/index.php
E:\phpStudy\PHPTutorial\WWW\bootstrap4wp/wp-content/themes/wp-bootstrap-4-pro-child-theme/page.php
使用:
include( get_home_template() );
1
來源:
wp-includes/template.php
其他類似函數:
get_privacy_policy_template()
get_embed_template()
get_singular_template()
get_search_template()
get_single_template()
get_attachment_template()
get_date_template()
get_home_template()
get_query_template()
get_front_page_template()
get_index_template()
get_page_template()
get_404_template()
get_archive_template()
get_post_type_archive_template()
get_author_template()
get_category_template()
get_tag_template()
get_taxonomy_template()