フォーラムへの返信

1件の返信を表示中 - 226 - 226件目 (全226件中)
  • フォーラム: プラグイン
    返信が含まれるトピック: サイドバー(ウィジェット)に余白を設定したい

    私も完全など素人なので全くわかりませんがプラグインではなくファンクションにウィジットとして追加するのではどうでしょうか。だめですか。
    こんな感じでできそうなと素人の浅知恵なのですが、WPの管理画面に質問があったので書き込んでみたくなった次第です。

    <?php
    class Widget_whitespace extends WP_Widget{
    //空白Widget
    function __construct() {
    parent::__construct(
    ‘Widget_whitespace’, // Base ID
    $GLOBALS[‘theme_title’].’ テーマ: 空白’, // Name
    array( ‘description’ => ‘サイドバーに空白を挿入します。’, ) // Args
    );
    }
    function form($instance) {
    $widget_space_height = esc_attr($instance[‘widget_space_height’]);
    ?>
    <p>
    なにもない空白ウィジットです。
    </p>
    <p>
    <label for=”<?php echo $this->get_field_id(‘widget_space_height’); ?>”>
    <?php _e(‘空白高さ:’); ?>
    </label>
    <input style=”width:80px;” id=”<?php echo $this->get_field_id(‘widget_space_height’); ?>” name=”<?php echo $this->get_field_name(‘widget_space_height’); ?>” type=”text” value=”<?php echo $widget_space_height; ?>” />
    px
    </p>
    <?php
    }
    function widget($args, $instance) {
    extract( $args );
    $widget_space_height = apply_filters( ‘widget_widget_space_height’, $instance[‘widget_space_height’] );
    $widget_space_height = esc_attr($instance[‘widget_space_height’]);
    ?>
    <div style=”height:<?php echo $widget_space_height; ?>px;”></div>
    <?php
    }
    function update($new_instance, $old_instance) {
    $instance = $old_instance;
    $instance[‘widget_space_height’] = trim(strip_tags($new_instance[‘widget_space_height’]));
    return $instance;
    }
    }
    add_action( ‘widgets_init’, function () { register_widget( ‘Widget_whitespace’ ); } );
    ?>

1件の返信を表示中 - 226 - 226件目 (全226件中)