首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress中的子主题不使用functions.php而不是@import加载

Wordpress中的子主题不使用functions.php而不是@import加载
EN

Stack Overflow用户
提问于 2017-07-20 02:36:22
回答 1查看 1.3K关注 0票数 1

我已经找了好几个问题,但仍然有麻烦。我非常感谢你们的一些专业知识。=)

在我的WordPress站点上创建和激活的子主题似乎没有进行任何更改。

我基本上知道零PHP,但是尝试使用functions.php而不是@import,因为它应该是一个更好的加载时间。

下面是我的子主题的目录style.css (第一)和functions.php (第二)中的内容

代码语言:javascript
复制
/*
Theme Name: Quest-Child
Description: No Coward's Quest Child Theme
Author: Jason from No Coward
Author URI: http://www.nocoward.com
Template: quest 
Version: 1.0
*/

/* add padding to site description */
.site-description {
    padding-top: 15px;
    padding-bottom: 30px;
}

.body {
    background: red;
}

/* can be found on "Services" page. Is the first ID within the <p> element */
#cc-m-12571703896 {
    background: blue;
}
代码语言:javascript
复制
<?php
function my_theme_enqueue_styles() {

    $parent_style = 'quest-all-css'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.

    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style ),
        wp_get_theme()->get('Version')
    );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>

WordPress识别子主题,并允许我成功地激活它。

CSS中的内容是我尝试用来测试我的子主题的东西,它记录了我的更改。什么都没有出现。

同样,我没有PHP知识。基于官方的WordPress“如何创建一个子主题”,我复制并粘贴了上面的代码,并试图根据他们的说明填写“父样式”值。

这是我在我的父母主题上看到的,我可能会用在functions.php的“父样式”上.

代码语言:javascript
复制
// Enqueue required styles
            wp_enqueue_style( 'quest-bootstrap', get_template_directory_uri() . '/assets/plugins/bootstrap/css/bootstrap.min.css' );
            wp_enqueue_style( 'smartmenus', get_template_directory_uri() . '/assets/plugins/smartmenus/addons/bootstrap/jquery.smartmenus.bootstrap.css' );
            wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/assets/plugins/font-awesome/css/font-awesome.min.css' );
            wp_enqueue_style( 'animate-css', get_template_directory_uri() . '/assets/plugins/animate/animate.css' );
            wp_enqueue_style( 'slit-slider', get_template_directory_uri() . '/assets/plugins/FullscreenSlitSlider/css/style.css' );
            wp_enqueue_style( 'colorbox', get_template_directory_uri() . '/assets/plugins/colorbox/colorbox.css' );
            wp_enqueue_style( 'Quest-style', get_stylesheet_uri(), array(
                'quest-bootstrap',
                'smartmenus',
                'font-awesome',
                'animate-css',
                'slit-slider',
                'colorbox'
            ) );

...

// Enqueue required styles
            wp_enqueue_style( 'quest-all-css', get_template_directory_uri() . '/assets/css/plugins-all.min.css' );
            wp_enqueue_style( 'Quest-style', get_stylesheet_uri(), array( 'quest-all-css' ) );

            // Enqueue required scripts
            wp_enqueue_script( 'quest-all-js', get_template_directory_uri() . '/assets/js/quest-and-plugins.js', array(
                'jquery',
                'masonry'
            ) );

我遗漏了什么?

提前谢谢!-Jason

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-23 20:19:28

我设法解决了这个问题。这是我在帮助论坛上找到的PHP代码。我认为“投资组合”的部分可能是无关的,但它是有效的,所以我把它留在那里以防万一。

代码语言:javascript
复制
<?php
add_action( 'wp_enqueue_scripts', 'quest_child_enqueue_styles' );
function quest_child_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
add_filter( 'quest_plus_template_content-portfolio', 'quest_child_template_portfolio' );

function quest_child_template_portfolio(){
    return get_stylesheet_directory() . '/content-portfolio.php';
}

请注意这个解决方案:有一件奇怪的事情正在发生。我添加了一些样式来制作“背景:红色”,这样我就可以测试子主题是否有效,尽管删除了这段代码,它仍然在出现。

目前,我认为这是慢托管,但请注意,如果您遵循这个解决方案。

希望这能帮到别人!

杰森

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45204134

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档