wordpress - 为不同的页面添加自定义样式表

时间:2014-01-03 07:44:08

标签: javascript php html css wordpress

我创建了名为“front-page.php”的自定义主页,并在header.php文件中添加了另一个带有自定义css和JS文件的页面:

<?php 
function my_styles_method() {

    if (is_page_template('front-page.php'==TRUE){  
    // Register the style like this for a theme:  
    wp_register_style( 'my-custom-style', get_template_directory_uri().'/includes/marquee.css');  

    // enqueue the stule  
    wp_enqueue_style( 'my-custom-style' );  

    }


    enter code here
    // Register the style like this for a theme:  
    if (is_page_template('our-story.php'==TRUE) {
    wp_register_style( 'my-custom-style', get_template_directory_uri().'/includes/main.css');  

    // enqueue the stule  
    wp_enqueue_style( 'my-custom-style' );
    }
}  
add_action( 'wp_enqueue_scripts', 'my_styles_method' ); 

?>

现在我在这个问题上面临以下问题: 当我在wordpress中运行时,我收到此错误消息:解析错误:语法错误,第32行的C:\ wamp \ www \ wordpress_update \ wp-content \ themes \ twentytwelve \ header.php中的意外“{”

我在两个网页上都创建了自定义模板

提前谢谢

1 个答案:

答案 0 :(得分:1)

试试这个

<?php 
    function my_styles_method() {

        if (is_page_template('front-page.php')==TRUE){  
        // Register the style like this for a theme:  
        wp_register_style( 'my-custom-style', get_template_directory_uri().'/includes/marquee.css');  

        // enqueue the stule  
        wp_enqueue_style( 'my-custom-style' );  

        }


        //enter code here
        // Register the style like this for a theme:  
        if (is_page_template('our-story.php')==TRUE) {
        wp_register_style( 'my-custom-style', get_template_directory_uri().'/includes/main.css');  

        // enqueue the stule  
        wp_enqueue_style( 'my-custom-style' );
        }

    add_action( 'wp_enqueue_scripts', 'my_styles_method' ); 

    ?>

// if(is_page_template('front-page.php'== TRUE)应为if(is_page_template('our-story.php')== TRUE)

相关问题