首页 > 解决方案 > 核心文件夹中带有下划线的 get_template_part()

问题描述

我需要一个文件的子副本listings_recently.php来对其进行更改。我需要将此文件包含到我的子主题中:/themes/listingeasy/core/widgets/listings_recently.php

据我所知,我需要告诉主题去寻找那个文件。那是在我孩子的主题中制作的,functions.php对吗?

所以这是我的functions.php

get_template_part('get_stylesheet_directory() . "/core/widgets/listings"', 'recently');
get_template_part('get_stylesheet_directory() . "/core/widgets/listings_recently.php"');

两条线都不工作。

我需要如何进行?这是文件夹架构:

themes
    listingeasy
        single.php
        core
            widgets
                listing_recently.php
    listingeasy-child
        functions.php
        single.php (I made changes here and its working)
        core
            widgets
                listing_recently.php (Changes here aren't working)

标签: wordpresstemplateswordpress-themingthemesparent-child

解决方案


我不知道你的主题。但是当您想编辑listings_recently.php 中的函数时,您可以尝试将这些函数复制到您的child-themes functions.php 并在那里进行编辑。大多数时候它都有效。

问候汤姆

编辑:尝试 require(); 在您的孩子主题functions.php中:

require('core/widgets/listings_recently.php');

编辑2(见评论,主题本身有自己的get_template_directory())

get_template_directory() 

返回父模板目录的路径。利用

get_stylesheet_directory() 

返回子主题目录的路径


推荐阅读