【问题标题】:Adding custom header and footer to wordpress blog将自定义页眉和页脚添加到 wordpress 博客
【发布时间】:2015-03-15 15:50:21
【问题描述】:

这里我有一个网站,tinywolf.uk,我目前正在开发。主页是一个独立于 wordpress 的静态站点,但站点 http://www.tinywolf.uk/blog 的博客部分将由 wordpress 提供支持。

我目前使用的是 251 主题,并且希望在博客的主页中也有页眉和页脚以保持连续性。

到目前为止,我已经创建了一个子主题,然后是一个包含主页标题的新 header.php 文件。这替换了现有的 wordpress header.php 并正确显示,但是,其余主题的样式已经消失。我想保持帖子的样式。

如何从二十五主题中调用正确的样式以确保内容(博客文章)的样式正确?

here 是我的子主题 header.php 代码

我尝试使用<link rel="stylesheet" 为二十五主题添加 style.css,尽管这会带来一些格式,但它也破坏了页面的结构。

这是我的functions.php的内容:

 <?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/blog/wp-content/themes/twentyfifteen/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/blog/wp-content/themes/twentyfifteen/style.css',
        array('parent-style')
    );
}
?>

这是我的孩子 style.css:

    /*
 Theme Name:   Tiny Theme Child
 Theme URI:    http://example.com/twenty-fifteen-child/
 Description:  Twenty Fifteen Child Theme
 Author:       Joel S
 Author URI:   http://www.tinywolf.uk/blog
 Template:     twentyfifteen
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
 Text Domain:  twenty-fifteen-child
*/

【问题讨论】:

    标签: css wordpress header stylesheet


    【解决方案1】:

    你必须在你的子主题中链接父主题 style.css。 这是来自 codex 的一个很好的例子

    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    }
    

    codex

    【讨论】:

    • 我已经从子文件夹中发布了我的 functions.php 和 style.ss。我应该在哪里插入上面的代码?
    • 我尝试加载父样式表,它对我有用,似乎样式表路径在您的代码中不正确
    • 感谢您的持续帮助 - 我的 style.css 的路径如下: /public_html/blog/wp-content/themes/twentyfifteen-child/style.css 用于子主题和 /public_html /blog/wp-content/themes/twentyfifteen/style.css 为父级。我尝试使用完整路径,也尝试使用 style.css,但两者都不起作用。让我确保缺少的是帖子的样式,而不是标题。
    • 可以用skype交流吗,更容易指导你
    • 我已经缩小了这个问题的范围并在这里转发:stackoverflow.com/questions/29065386/…
    【解决方案2】:

    如果我理解正确,您希望在 wp. 您唯一需要做的就是将静态页面中的两个部分复制到名为 header.phpfooter.php 的单独文件中,然后将代码更改为标题代码以成为动态 WP 代码。 之后将他们召集到您的团队中。

    但是, 如果您想使用子主题,请这样做:

    按照上述所有步骤并将文件命名为例如header-child.php & footer-child.php 然后这样称呼他们:&lt;?php get_header('child'); ?&gt;

    记住:页眉和页脚必须是文件名的第一个,你不能像child-header.php 一样。不会工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-22
      • 1970-01-01
      • 2017-06-19
      • 1970-01-01
      • 1970-01-01
      • 2015-12-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多