1

Devin Price の Options Framework テーマを使用して、テーマ オプションに CSS スタイル スイッチャーを追加する際に問題があります。すべてうまくいっているように見えますが、オプションを出力すると、実際のファイル名の代わりに 1.css 2.css 3.css が得られます。

これが私がすることです:

「styles」ディレクトリ内のすべてのスタイルシートを配列にプルします。

$alt_stylesheet_path = get_template_directory() . '/styles/';
$alt_stylesheets = array();
if ( is_dir($alt_stylesheet_path) ) {
    if ($alt_stylesheet_dir = opendir($alt_stylesheet_path) ) {
        while ( ($alt_stylesheet_file = readdir($alt_stylesheet_dir)) !== false ) {
            if(stristr($alt_stylesheet_file, ".css") !== false) {
                $alt_stylesheets[] = $alt_stylesheet_file;
            }
        }
    }
}

次に、オプションパネルを作成します

$options[] = array(
    'name' => __('StyleSheet', 'mytheme'),
    'desc' => __('Select a color scheme', 'mytheme'),
    'id' => 'alt_stylesheet',
    'type' => 'select',
    'options' => $alt_stylesheets,
    "std" => "default.css");

そして、header.phpでこのように呼び出します

<link rel="stylesheet" href="<?php echo bloginfo('template_directory')?>/styles/<?php echo of_get_option('alt_stylesheet'); ?>.css" type="text/css" media="screen" />

オプション ID (1.css、2.css) の代わりに css ファイル名 (例: green.css blue.css) を出力するにはどうすればよいですか?

私はすでに一日を失ってしまったので、どんな助けも大歓迎です。ありがとうございました

4

0 に答える 0