2012-08-17 23 views
0

我第一次構建完整的設計到WordPress,我試圖加載樣式表和腳本文件,但我似乎得到的是文本輸出的位置。有WordPress的問題wp_enqueue_style

我有什麼是低於..

wp_enqueue_style('reset', bloginfo('template_url') . '/reset.css'); 
wp_enqueue_style('style', bloginfo('stylesheet_url'), array('reset')); 
wp_enqueue_style('rhino', bloginfo('template_url') . '/rhinoslider-1.05.css', array('reset','style')); 

我需要把這個link標籤或裏面的東西?我認爲它會自己做到這一切;如果它自己沒有這樣做,那麼加載它的意義是什麼?我知道它確保同一個文件不會被包含兩次,但如果你必須自己包含鏈接標記,然後WP決定不包含這個文件,那麼你留下了空白的鏈接標記!?

最後,我應該事先設置這些,所以我可以通過他們的手柄調用它們嗎?如果是這樣,在哪裏? functions.php?

編輯:我也試過把下面放在我的主題functions.php文件中,但得到了相同的結果。

add_action('after_setup_theme', 'mmw_new_theme_setup'); 

function mmw_new_theme_setup() { 

    /* Add theme support for post formats. */ 
    add_theme_support('post-formats'); 

    /* Add theme support for post thumbnails. */  
    add_theme_support('post-thumbnails'); 

    /* Add theme support for automatic feed links. */ 
    add_theme_support('automatic-feed-links'); 

    /* Add theme support for menus. */ 
    add_theme_support('menus'); 

    /* Load style files on the 'wp_enqueue_scripts' action hook. */ 
    add_action('wp_enqueue_scripts', 'mmw_new_load_styles'); 

} 

function mmw_new_load_styles() { 

    $foo = bloginfo('template_url') . '/reset.css'; 
    $bar = bloginfo('template_url') . '/rhinoslider-1.05.css'; 

    wp_enqueue_style('reset', $foo); 
    wp_enqueue_style('style', bloginfo('stylesheet_url'), array('reset')); 
    wp_enqueue_style('rhino', $bar, array('reset','style')); 

} 

回答

1

當通過PHP使用的變量存儲值:

get_bloginfo()

所以你的新函數現在看起來像:

function mmw_new_load_styles() { 

    $foo = get_bloginfo('template_url') . '/reset.css'; 
    $bar = get_bloginfo('template_url') . '/rhinoslider-1.05.css'; 

    wp_enqueue_style('reset', $foo); 
    wp_enqueue_style('style', bloginfo('stylesheet_url'), array('reset')); 
    wp_enqueue_style('rhino', $bar, array('reset','style')); 

} 

而且更有語義!它使初學者的代碼更易於查看。 ($ foo可能是$ resetCssUrl)

0

我有類似的問題。

寄存器/入隊腳本使您可以全局地分配函數以正確的順序裝入。你可以從你工作的那個網頁打電話給他們,但這被認爲是更好的做法。

我的模板有一個functions.php,但它的nealry是空的!它將腳本分爲七個子章節,主題選項,主題功能,主題-js等等。這裏是我的themes.js.php文件,但它可以很容易地放在你的文件內部的wp-content/themes/functions中。 PHP My themes-js.php file

+0

您似乎正在以類似的方式嘗試。我已經用我嘗試的另一種方法更新了我的帖子,但是我得到了相同的結果。 – Brett 2012-08-18 17:21:33