echoで変数を出力できません
-
カテゴリーに入力フィールドを作成したく、以下をfunctions.phpに追加しました。
<?php add_action ( 'edit_category_form_fields', 'extra_category_fields'); //カテゴリ編集ページに、入力フィールド追加 function extra_category_fields( $tag ) { $t_id = $tag->term_id; $cat_meta = get_option("cat_$t_id"); ?> <tr class="form-field"> <th><label for="extra_text">Title</label></th> <td><input type="text" name="Cat_meta[extra_text]" id="extra_text" size="25" value="<?php if(isset ( $cat_meta['extra_text'])) echo esc_html($cat_meta['extra_text']) ?>" /></td> </tr> <tr class="form-field"> <th><label for="extra_text02">Description</label></th> <td><textarea name="Cat_meta[extra_text02]" id="extra_text02" ><?php if(isset ( $cat_meta['extra_text02'])) echo esc_html($cat_meta['extra_text02']) ?></textarea></td> </tr> <tr class="form-field"> <th><label for="extra_text03">Keywords</label></th> <td><input type="text" name="Cat_meta[extra_text03]" id="extra_text03" size="25" value="<?php if(isset ( $cat_meta['extra_text03'])) echo esc_html($cat_meta['extra_text03']) ?>" /></td> </tr> <?php } add_action ( 'edited_term', 'save_extra_category_fileds'); //保存処理 function save_extra_category_fileds( $term_id ) { if ( isset( $_POST['Cat_meta'] ) ) { $t_id = $term_id; $cat_meta = get_option( "cat_$t_id"); $cat_keys = array_keys($_POST['Cat_meta']); foreach ($cat_keys as $key){ if (isset($_POST['Cat_meta'][$key])){ $cat_meta[$key] = $_POST['Cat_meta'][$key]; } } update_option( "cat_$t_id", $cat_meta ); } }
管理画面のカテゴリーページにはちゃんと入力フィールドが表示されており、header.phpに下記のように記述したのですが、値が出力されません。
<?php $cate_all = get_terms("category", "fields=all"); $cat_data = get_option('cat_'.intval($cat_all[0]->term_id)); $title = esc_html($cat_data['extra_text']); $description = esc_html($cat_data['extra_text02']); $keywords = esc_html($cat_data['extra_text03']); echo $keywords; ?>
extra_text03をkeywordsという変数に置き換え、それをechoで出力ということだと思うのですが、なぜ表示されないのでしょうか?
もしかしたら、前置き云々ではなく、基本的な話かもしれませんが、よろしくお願いします。
2件の返信を表示中 - 1 - 2件目 (全2件中)
2件の返信を表示中 - 1 - 2件目 (全2件中)
- トピック「echoで変数を出力できません」には新たに返信することはできません。