Creating Widget with html Not sure not stable…
-
<?php class Weekly_Material_Schedule_Widget extends WP_Widget { static $materialsData; // マスターデータを保存する静的変数 public function __construct() { parent::__construct( 'weekly_material_schedule_widget', 'Weekly Material Schedule Widget', array( 'description' => 'Display the weekly material farming schedule.' ) ); // マスターデータの読み込み if ( ! isset( self::$materialsData ) ) { self::$materialsData = get_weekly_materials_data(); } } public function widget( $args, $instance ) { echo $args['before_widget']; // タイトルが指定されている場合、ウィジェットタイトルを表示 if ( ! empty( $instance['title'] ) ) { echo $args['before_title'] . esc_html( $instance['title'] ) . $args['after_title']; } // ウィジェットの HTML 表示 echo '<div class="farming-schedule" id="farmingSchedule">'; // 以下のスクリプトはそのまま // 名前で比較 usort(self::$materialsData, function ($a, $b) { return strcmp($a['name'], $b['name']); }); $today = date('l'); // 今日の曜日を取得 $displayedIcons = []; // すでに表示されたアイコンの名前を保持する配列 $farmingSectionDisplayed = false; // farming-section charactersが表示されたかどうかのフラグ foreach (self::$materialsData as $set) { if (in_array($today, explode(', ', $set['days']))) { // farming-section charactersがまだ表示されていない場合 if (!$farmingSectionDisplayed) { echo "<div class='farming-section characters'>"; // farming-section charactersを開始 $farmingSectionDisplayed = true; // フラグを立てて表示済みとする echo " <div class='farming-list'>"; // farming-listを開始 } // 以下のアセンション素材表示のコードはそのまま // 各アセンション素材に対するアイコン名を取得し、重複表示を防ぐために$displayedIconsに追加する $iconKey = $set['name']; // 現在のアセンション素材のアイコン名 $displayedIcons[] = $iconKey; // 表示済みのアイコンの配列に追加 } } if ($farmingSectionDisplayed) { // farming-section charactersが表示されている場合 // farming-listの終了 echo " </div>"; // farming-section charactersの終了 echo " </div>"; } // ウィジェットの HTML 表示終了 echo '</div>'; // farming-schedule の終了 echo $args['after_widget']; } } // ウィジェットの登録 add_action('widgets_init', function(){ register_widget('Weekly_Material_Schedule_Widget'); });
Creating Widget with html Not sure not stable… Once read from data from function.php but i changed
Before works this code read data shown HTML too
echo ‘<div class=”farming-schedule” id=”farmingSchedule”>’;
After changed <div> not sure doesnot read data not shown Widget Title even
echo ‘<div class=”farming-schedule” id=”farmingSchedule”</div>’;
Not sure Take lots time Help me.. wordpress is hard..
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Creating Widget with html Not sure not stable…’ is closed to new replies.