Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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
Php 正确定义子样式和javascript_Php_Wordpress - Fatal编程技术网

Php 正确定义子样式和javascript

Php 正确定义子样式和javascript,php,wordpress,Php,Wordpress,我正在使用wordpress 4.9.5,我在functions.php我的样式中排队,如下所示: function enqueue_parent_theme_style() { if ( is_page( 'product builder' ) || is_page('shopping products')) { $parentStyle = 'parent-style'; //css wp_enqueue_style($paren

我正在使用wordpress 4.9.5,我在
functions.php
我的样式中排队,如下所示:

function enqueue_parent_theme_style()
{
    if ( is_page( 'product builder' )  || is_page('shopping products')) {

        $parentStyle = 'parent-style';

        //css
        wp_enqueue_style($parentStyle, get_template_directory_uri() . '/style.css');
        wp_enqueue_style('bootstrap-4.0.0', get_stylesheet_directory_uri() . '/css/bootstrap.min.css', array($parentStyle));
        wp_enqueue_style('dataTables', '//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css', array($parentStyle) );
        wp_enqueue_style('dataTables-1.10.16', get_stylesheet_directory_uri() . '/css/dataTables.bootstrap4.min.css', array($parentStyle));

        //js
        wp_enqueue_script('font-awesome', 'https://use.fontawesome.com/releases/v5.0.10/js/all.js', NULL, '1.0', true);
        wp_enqueue_script('main-shopping-product-js', get_theme_file_uri('/js/scripts-bundled.js'), NULL, '1.0', true);

        wp_localize_script('main-shopping-product-js', 'shoppingproductData', array(
            'root_url' => get_site_url(),
            'nonce' => wp_create_nonce('wp_rest')
        ));
    }
}

add_action('wp_enqueue_scripts', 'enqueue_parent_theme_style');
如您所见,我只想在两个子页面上加载我的子css/javascript,
product builder
shopping products
。我的css/javascript在以下两个页面上工作:

在我的两个子页面上,主题的css和javascript工作得非常好。然而,当我回到我的主主题页面时,css和javascript被破坏了

页面如下所示:

function enqueue_parent_theme_style()
{
    if ( is_page( 'product builder' )  || is_page('shopping products')) {

        $parentStyle = 'parent-style';

        //css
        wp_enqueue_style($parentStyle, get_template_directory_uri() . '/style.css');
        wp_enqueue_style('bootstrap-4.0.0', get_stylesheet_directory_uri() . '/css/bootstrap.min.css', array($parentStyle));
        wp_enqueue_style('dataTables', '//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css', array($parentStyle) );
        wp_enqueue_style('dataTables-1.10.16', get_stylesheet_directory_uri() . '/css/dataTables.bootstrap4.min.css', array($parentStyle));

        //js
        wp_enqueue_script('font-awesome', 'https://use.fontawesome.com/releases/v5.0.10/js/all.js', NULL, '1.0', true);
        wp_enqueue_script('main-shopping-product-js', get_theme_file_uri('/js/scripts-bundled.js'), NULL, '1.0', true);

        wp_localize_script('main-shopping-product-js', 'shoppingproductData', array(
            'root_url' => get_site_url(),
            'nonce' => wp_create_nonce('wp_rest')
        ));
    }
}

add_action('wp_enqueue_scripts', 'enqueue_parent_theme_style');

有什么建议我做错了什么

更新

我的浏览器控制台显示以下内容:

function enqueue_parent_theme_style()
{
    if ( is_page( 'product builder' )  || is_page('shopping products')) {

        $parentStyle = 'parent-style';

        //css
        wp_enqueue_style($parentStyle, get_template_directory_uri() . '/style.css');
        wp_enqueue_style('bootstrap-4.0.0', get_stylesheet_directory_uri() . '/css/bootstrap.min.css', array($parentStyle));
        wp_enqueue_style('dataTables', '//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css', array($parentStyle) );
        wp_enqueue_style('dataTables-1.10.16', get_stylesheet_directory_uri() . '/css/dataTables.bootstrap4.min.css', array($parentStyle));

        //js
        wp_enqueue_script('font-awesome', 'https://use.fontawesome.com/releases/v5.0.10/js/all.js', NULL, '1.0', true);
        wp_enqueue_script('main-shopping-product-js', get_theme_file_uri('/js/scripts-bundled.js'), NULL, '1.0', true);

        wp_localize_script('main-shopping-product-js', 'shoppingproductData', array(
            'root_url' => get_site_url(),
            'nonce' => wp_create_nonce('wp_rest')
        ));
    }
}

add_action('wp_enqueue_scripts', 'enqueue_parent_theme_style');

问题在于
style.css
,它位于:

style.css
文件包含所有css规则(也包括菜单部分),这些规则构成页面布局。从零件将在所有页面中加载
style.css
文件的条件移出:

function enqueue_parent_theme_style()
{
    $parentStyle = 'parent-style';
//css
    wp_enqueue_style($parentStyle, get_template_directory_uri() . '/style.css');

    if (is_page('product builder') || is_page('shopping products')) {
        wp_enqueue_style('bootstrap-4.0.0', get_stylesheet_directory_uri() . '/css/bootstrap.min.css', array($parentStyle));
        wp_enqueue_style('dataTables', '//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css', array($parentStyle));
        wp_enqueue_style('dataTables-1.10.16', get_stylesheet_directory_uri() . '/css/dataTables.bootstrap4.min.css', array($parentStyle));

//js
        wp_enqueue_script('font-awesome', 'https://use.fontawesome.com/releases/v5.0.10/js/all.js', NULL, '1.0', true);
        wp_enqueue_script('main-shopping-product-js', get_theme_file_uri('/js/scripts-bundled.js'), NULL, '1.0', true);

        wp_localize_script('main-shopping-product-js', 'shoppingproductData', array(
            'root_url' => get_site_url(),
            'nonce' => wp_create_nonce('wp_rest')
        ));
    }
}

add_action('wp_enqueue_scripts', 'enqueue_parent_theme_style');

看看浏览器控制台。有多少404错误?您正在有条件地加载主题的主
style.css
,这就是主页上没有样式/js的原因。您是否只希望在这些产品页面上显示主题样式?好的,请在页面中进行检查,如果加载了bootstrap.css文件(它的任何版本),您的意思是什么
不出现bootstrap
?您能否将所有
wp\u enqueue\u样式的
函数移出
if
语句。页面仍显示“已断开”@SamvelAleqsanyan请将其添加为答案,以便我可以接受它!