Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html Wordpress:处理Child和amp;父主题_Html_Css_Wordpress_Twitter Bootstrap - Fatal编程技术网

Html Wordpress:处理Child和amp;父主题

Html Wordpress:处理Child和amp;父主题,html,css,wordpress,twitter-bootstrap,Html,Css,Wordpress,Twitter Bootstrap,我开始在wordpress网站上工作。在选择了一个主题之后,我决定用子主题的方式来定制它 我采用了以下常用方法: add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); function theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() .'/style.css'); wp_enqueue_

我开始在wordpress网站上工作。在选择了一个主题之后,我决定用子主题的方式来定制它

我采用了以下常用方法:

add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );

function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() .'/style.css');
    wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ) );
}
使用它时,效果并不好,因为我的父级已经有了一个包含大量CSS样式表的排队函数,而且顺序很重要,特别是关于引导CSS,它必须被父级样式表覆盖

从这里开始,有两种解决方案:

  • 复制并粘贴整个排队父函数(因此我们用子函数替换父函数。对我来说,赞成的是我们保持队列的原始顺序,反对的是我们完全跳过可以更新的原始函数

  • 将此代码用作子排队函数:

       function theme_enqueue_styles() {
       wp_deregister_style('zerif_bootstrap_style');
       wp_enqueue_style('zerif_bootstrap_style', get_template_directory_uri() . '/css/bootstrap.css');
       wp_enqueue_style( 'zerif-style', get_template_directory_uri() . '/style.css'    );
       wp_enqueue_style( 'cleverdrive-style', get_stylesheet_uri(), array( 'zerif-style' ) );
       }
    
在我的情况下,它看起来工作得很好,但如果取消注册样式的原始顺序很重要,我认为我们不会保留它

根据你的说法,处理这个案件的最佳方式是什么

谢谢你


Sommy

尝试在子主题中使用不同的函数,但使用更高优先级的
wp\u enqueue\u脚本或
wp\u footer
钩子,在这里输入额外的js
css
文件。这样可以保持父主题函数工作,子主题函数也可以工作。

您可以尝试enque吗使用不同的函数在子主题中添加额外的js和css文件,但
wp\u enqueue\u脚本
具有更高的优先级或
wp\u footer
hook。这将保持父主题函数正常工作,子主题函数也正常工作。您好,它工作了!简单高效,完美!感谢您将我的评论标记为有用您的问题已经解决。我已经添加了答案,请将其标记为解决方案,以便对其他人有所帮助。第一次使用Stackoverflow时,我搜索了如何解决此主题,现在我知道:-)Thx