2017-10-05 99 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

谢谢,它工作:) –