Php 调用子目录中的页面模板

Php 调用子目录中的页面模板,php,html,wordpress,wordpress-theming,Php,Html,Wordpress,Wordpress Theming,我有一个html的多语言静态网站。因此,我根据选择的语言创建了几个子目录,这是语言的“lang”文件夹,法语的“fr”文件夹和西班牙语的“es”文件夹。但是,我不知道如何从控制面板调用WordPress中的模板页面,因为这些页面位于另一个文件夹中 我已经评估了这个问题,我知道这是3.4版本中的一个选项,您必须在主题的根目录中创建一个页面模板文件夹,但在我的情况下,我只能看到主题根目录中的模板页面,而不能看到子目录中的模板页面 现在我的目录系统是: wp content->themes->myte

我有一个html的多语言静态网站。因此,我根据选择的语言创建了几个子目录,这是语言的“lang”文件夹,法语的“fr”文件夹和西班牙语的“es”文件夹。但是,我不知道如何从控制面板调用WordPress中的模板页面,因为这些页面位于另一个文件夹中

我已经评估了这个问题,我知道这是3.4版本中的一个选项,您必须在主题的根目录中创建一个页面模板文件夹,但在我的情况下,我只能看到主题根目录中的模板页面,而不能看到子目录中的模板页面

现在我的目录系统是:

wp content->themes->myteme->[page templates folder]-index.php/style.css->[lang folder]->[es folder]-关于_me.php


任何帮助都将不胜感激。

WordPress仅在主题目录和下面的一级搜索模板。要想做你想做的事,你需要适应这一点。例如:

/themes/myTheme
    /templates-en
    /templates-es
    ...

嗯。在我看来,你有两个选择

1.不要为不同的语言使用特定的页面模板。 更好的方法是使用wordpress已经提供的翻译选项

要了解更多信息,您至少应该阅读:

  • 2.通过使用数组或其他方法来转换您自己的方式 您可以轻松地用php创建自己的语言文件,并将语言翻译写入数组以翻译您的站点

    示例:

    文件1-语言EN.php

    $language_array = array(
      "hello" => "hello",
      "world" => "world"
    );
    
    $language_array = array(
      "hello" => "hallo",
      "world" => "wereld"
    );
    
    $language = "nl";
    if($language = "nl")
    {
        include 'language-nl.php';
    }
    elseif ($language = "en")
    {
        include 'language-en.php';
    }
    echo $language["hello"];
    
    <?php
    /*
    Template Name: My Custom Page
    */
    
    include get_template_directory() . "/subdirectory/subpage-custom.php";
    
    <?php echo "Your code goes here"; ?>
    
    文件2-语言NL.php

    $language_array = array(
      "hello" => "hello",
      "world" => "world"
    );
    
    $language_array = array(
      "hello" => "hallo",
      "world" => "wereld"
    );
    
    $language = "nl";
    if($language = "nl")
    {
        include 'language-nl.php';
    }
    elseif ($language = "en")
    {
        include 'language-en.php';
    }
    echo $language["hello"];
    
    <?php
    /*
    Template Name: My Custom Page
    */
    
    include get_template_directory() . "/subdirectory/subpage-custom.php";
    
    <?php echo "Your code goes here"; ?>
    
    文件3-Page Template.php

    $language_array = array(
      "hello" => "hello",
      "world" => "world"
    );
    
    $language_array = array(
      "hello" => "hallo",
      "world" => "wereld"
    );
    
    $language = "nl";
    if($language = "nl")
    {
        include 'language-nl.php';
    }
    elseif ($language = "en")
    {
        include 'language-en.php';
    }
    echo $language["hello"];
    
    <?php
    /*
    Template Name: My Custom Page
    */
    
    include get_template_directory() . "/subdirectory/subpage-custom.php";
    
    <?php echo "Your code goes here"; ?>
    
    或者(如果您确定$language变量设置正确)

    3.如您所问:从子目录加载模板 示例:

    在主题根目录中创建页面模板

    文件:page custom.php

    $language_array = array(
      "hello" => "hello",
      "world" => "world"
    );
    
    $language_array = array(
      "hello" => "hallo",
      "world" => "wereld"
    );
    
    $language = "nl";
    if($language = "nl")
    {
        include 'language-nl.php';
    }
    elseif ($language = "en")
    {
        include 'language-en.php';
    }
    echo $language["hello"];
    
    <?php
    /*
    Template Name: My Custom Page
    */
    
    include get_template_directory() . "/subdirectory/subpage-custom.php";
    
    <?php echo "Your code goes here"; ?>
    
    
    

    现在,您可以从post editor(属性下)选择页面模板。

    购买插件是一种选择吗?WPML可以为您提供所需的选项。@Leonidas谢谢您的回答。我不是在寻找翻译页面的插件,而是从控制面板中选择一个子目录中的模板页面的方法。现在,我只能对根目录中的页面执行此操作。@Masiorama的可能副本在发布我的问题之前,我访问了该帖子并创建了一个名为“页面模板”的文件夹,但我无法从控制面板中看到任何模板页面,只有那些页面在根目录中。好的,抱歉,不清楚。您是否尝试创建“页面模板”文件夹并用模板填充它?你能从那里看到模板吗?到目前为止,我的目录如下:wp-content/themes/myteme/page-templates/index.php我想通过这种结构,我的控制面板应该向我显示选择要选择但不起作用的模板的组合。这是从零开始的主题,我应该做些别的吗?需要任何文件吗?WordPress正在查看以“问题已解决。我必须使用”开头的.php文件,包括get_template_directory()“从子目录调用我的php。非常感谢。非常感谢你的回答和你的时间!我的问题与您的第三点有关,它与get_template_目录完美配合。不管怎样,我会注意另一个。