【问题标题】:Wordpress Include template in another oneWordpress 在另一个模板中包含模板
【发布时间】:2021-03-18 00:56:36
【问题描述】:

我有一个自定义 wordpress 模板,我想在其中包含另一个模板。 基本上我有一个审核表单,我想在其中包含一个字段来编辑用户显示名称,并且该字段位于另一个模板中。

这是我的文件夹结构:

  • 子主题/

    用户显示名称模板.php

    • 审阅模板文件夹/

      review-template.php

我想在 review-template.php 中包含 user-display-name-template.php(即在子文件夹 review-template-folder 中) 获得此结果的最佳方法是什么。 感谢您的帮助。

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案1】:

    您是否尝试过使用“get_template_part”?

    https://developer.wordpress.org/reference/functions/get_template_part/

    所以在你的情况下你会使用:

    get_template_part('user-display-name-template');
    

    【讨论】:

    • 试过但它返回“抱歉,没有找到页面。”
    • 您不会收到关于模板包含的错误,这听起来像是潜在的永久链接问题
    • 我设法找到了问题,这是包含的模板本身的一个 if 条件。现在它工作正常。谢谢。
    猜你喜欢
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    • 2012-08-15
    • 2015-11-30
    • 2018-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多