【问题标题】:want to add different header file to custom template想要将不同的头文件添加到自定义模板
【发布时间】:2016-05-09 21:08:45
【问题描述】:

我想为自定义 wordpress 页面模板添加不同的头文件。 我为自定义帖子类型创建了一个新模板。我想使用 get_header() 函数向其中添加头文件,但不想使用主题的常规头文件。我可以将整个更改的头文件粘贴到模板中,但我认为这不是正确的方法。任何建议都会有所帮助。

谢谢

【问题讨论】:

  • 正确的方法是添加到您的header.php 文件中,条件条件将检查您所在的页面是否是自定义模板,并加载它自己的菜单以及您想要的任何内容。

标签: wordpress templates


【解决方案1】:

您可以为每个模板创建头文件,例如,调用 header-blog.php: 你需要get_header('blo');

【讨论】:

  • 例如调用header-blog.php:需要get_header('blog');
【解决方案2】:

我建议只根据模板替换头文件中的内容。 因此,您可以像这样为模板“about.php”添加一个块:

if(is_page_template( 'templates/about.php' ) {
    //custom header for about.php

} else {
    //Header for all other pages

}

【讨论】:

    【解决方案3】:

    您只需在当前主题中创建一个不同的头文件 就像 header-custom.php 一样

    这个例子将包含 header-custom.php

    <?php
    get_header('custom');
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-13
      • 1970-01-01
      • 2016-07-02
      • 1970-01-01
      • 2020-09-23
      • 2013-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多