0

WordPress初めて完全なデザインを構築し、スタイルシートとスクリプト ファイルを読み込もうとしていますが、場所のテキスト出力しか得られないようです。

私が持っているものは以下です..

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ますか?私はそれがすべてそれ自体で行うと思っていました。それ自体を行わない場合、そのようにロードするポイントは何ですか?同じファイルが2回または何か含まれていないことを確認していますが、リンクタグを自分で含める必要があり、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'));

}
4

2 に答える 2

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 の可能性があります)

于 2012-08-20T21:55:52.197 に答える
0

私は同様の問題を抱えていました。

register / enqueue スクリプトは、関数をグローバルに割り当てて正しい順序でロードできるようにするためのものです。作業しているページからそれらを呼び出すことができますが、この方法で行うことをお勧めします。

私のテンプレートには functions.php がありますが、ほとんど空です! スクリプトをテーマ オプション、テーマ関数、テーマ js などの 7 つのサブチャプターに分けます。 php 私のthemes-js.phpファイル

于 2012-08-18T13:15:42.143 に答える