サポート » プラグイン » サイドバー(ウィジェット)に余白を設定したい

  • お世話になっております。
    当方wordpressの初心者で、現在Oxygenを使用して制作しております。
    どうかお知恵をお貸し頂ければと思い、投稿させていただきました。

    現在、サイトの左横にサイドバー(ウィジェット)にImage Widgetを利用して
    バナーを追加する作業をしております。
    しかし、縦並びでバナーを追加していくと、バナーの画像と画像の間の余白を設定することができず、
    ぴったりとくっついたデザインになってしまいます。
    そこで「ytbd yohaku」(http://yotsuba-d.com/blog/wordpressのウィジェット間の余白を調整できるプラグイ/)
    からプラグインをダウンロードして余白を設定しようと考えたのですが、
    下記のようなエラーメッセージが出てしまい、対処することができません。

    ————————————————————————
    Notice: Undefined index: wdmubody in /home/users/1/サイト名などの階層/wp-content/plugins/ytbd_yohaku.php on line 30
    ————————————————————————

    php全体のテキストは以下になります。

    ————————————————————————
    <?php
    /*
    Plugin Name: ytbd yohaku
    Plugin URI:
    Description: ウィジェットに余白を設定します。
    Version: 1.0
    Author: kenji goto
    Author URI: http://yotsuba-d.com
    License: GPL
    */
    ?>
    <?php
    class YTBWidgetmargin extends WP_Widget {
    function YTBwidgetmargin() {
    parent::__construct(false, $name = ‘余白’ );
    }
    function widget($args, $instance) {
    extract( $args );
    $body = apply_filters( ‘widget_body’, $instance[‘wdmubody’] );
    ?>
    <?php echo ‘<div style=”margin-bottom:’ . $body . ‘px; “></div>’; ?>
    <?php
    }
    function update($new_instance, $old_instance) {
    $instance = $old_instance;
    $instance[‘wdmubody’] = trim($new_instance[‘wdmubody’]);
    return $instance;
    }
    function form($instance) {
    $body = esc_attr($instance[‘wdmubody’]);
    ?>

    <p>
    <label for=”<?php echo $this->get_field_id(‘wdmubody’); ?>”>
    <?php _e(‘数値を入力※px指定(例:10)’); ?>
    </label>
    <input class=”widefat” type=”text” id=”<?php echo $this->get_field_id(‘wdmubody’); ?>” name=”<?php echo $this->get_field_name(‘wdmubody’); ?>” />
    <?php echo ‘現在の余白’.$body.’px’; ?>
    </p>
    <?php
    }
    }
    add_action(‘widgets_init’, create_function(”, ‘return register_widget(“YTBwidgetmargin”);’));
    ?>
    ————————————————————————

    30行目にエラーがあるとは思うんですが、なにが書かれていてどう対処すればいいのか全くわからない状況です。
    補足としては、15行目にある
    parent::__construct(false, $name = ‘余白’ );
    の部分は、もともと
    parent::WP_Widget(false, $name = ‘余白’ );
    だったのですが、エラーが出てしまったので「WP_Widget」の部分だけ修正しました。

    以上のような状況なのですが、どなたか解決できる方はいらっしゃいますでしょうか?
    すみませんがご教示いただければ幸いです。
    どうぞよろしくお願いいたします。

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • 私も完全など素人なので全くわかりませんがプラグインではなくファンクションにウィジットとして追加するのではどうでしょうか。だめですか。
    こんな感じでできそうなと素人の浅知恵なのですが、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件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック「サイドバー(ウィジェット)に余白を設定したい」には新たに返信することはできません。