2017-10-05 94 views
2

我在header.php中使用get_template_part('theme-templates/opt_header1')函數,並在opt_header1.php中再次使用get_template_part('carousal')函數。然而,header.php中的get_template_part('theme-templates/opt_header1')函數工作正常,但我想使用另一個模板部分opt_header1.php這是carousal.php,但它不工作。get_template_part不工作 - WordPress

文件夾結構是像下面...

[文件夾]

 [template-part] 

    ... opt_header1.php 

    ... carousal.php 

    [/template-part] 

..header.php

[/文件夾]

使用...

get_template_part('carousal'); 

ple ase幫助:)

回答

2

您需要告訴get_template_part()參考主題的根目錄添加的文件的路徑。

所以,你需要這樣做:

get_template_part('theme-templates/carousal'); 

瞞着get_template_part文件(carousal.php),該功能正在尋找的相對路徑(和失敗)在carousal.php:

  1. 兒童主題/ carousal.php
  2. 父主題/ carousal.php
+0

感謝您的快速回復。但讓我告訴你,我想在** opt_header1.php中使用** carousal **這兩個文件都在它們的根上。 我仍然需要添加「主題模板/」? –

+0

是的,你:) 請注意主題的根是主題文件夾。 '主題模板'是一個子文件夾。 get_template_part函數需要被告知要從主題的根視角相應添加的文件 - 無論您在子文件夾內部有多深。 –

+0

謝謝,它工作:) –