1

だから私はウィジェットを作るのが初めてです。いくつかのチュートリアルに従って、ついに独自のカスタム ウィジェットを作成することができました (やった!)。しかし、なぜかテーマのスタイリングを引っ張っていない?

いくつかのテーマで試しましたが、常に同じです。私が追加する他のすべてのウィジェットは、サイドバーのテーマ スタイルを取得しますが、カスタムのものにはスタイルがありません (コーディングに配置した div スタイルを除く)。

ウィジェットにテーマ スタイルを強制的にプルさせるためにどこかに追加する必要がある特定のコードはありますか?

申し訳ありませんが、追加したかっただけです-このウィジェットをファンサイトを運営している数人の友人に提供したいので、任意のテーマからスタイルを自動的に取得したいと考えています.

前もって感謝します!

申し訳ありませんが、それを追加するとは思いませんでした。私が使用しているコードは次のとおりです。

            class Current_Projects extends WP_Widget
    {

      public function __construct()
      {
        parent::__construct(
          'current-projects',
          'Current Projects',
          array(
            'description' => 'Current Projects'
          )
        );
      }

      public function widget( $args, $instance )
      {
        // output
        echo ' 
          <div style="padding:5px;margin:0auto;width:260px;text-align:left;margin-        right:10px;"><img width="25%" float="left"  src="'.esc_textarea($instance['image_uri']).'"         />
          <div style="float:right;width:65%"><div style="padding-top:0px;line-height:14px;        padding-right:10px;"><b>Project: </b>'.esc_textarea($instance['text']).'</div>
          <div style="padding-top:0px;line-height:14px;padding-right:10px;;"><b>Date:         </b>'.esc_textarea($instance['date']).'</div>
          <div style="padding-top:0px;line-height:14px;padding-right:10px;"><b>As:         </b>'.esc_textarea($instance['role']).'</div></div>
          <div style="padding-top:10px;        line-height:14px;">'.esc_textarea($instance['summary']).'</div>
          <div style="padding-top:10px;line-height:14px;"><a         href="'.esc_textarea($instance['imdb']).'">IMDB</a> &bull; <a         href="'.esc_textarea($instance['official']).'">Official Site</a> &bull; <a         href="'.esc_textarea($instance['gallery']).'">Gallery</a></div>


          <br /><br /></div>
                ';
      }

      public function form( $instance )
      {
        // new instances
        ?>
        <p>
          <label for="<?php echo $this->get_field_id('text'); ?>">Project Title</label><br />
          <input type="text" name="<?php echo $this->get_field_name('text'); ?>" id="<?php         echo $this->get_field_id('text'); ?>" value="<?php echo $instance['text']; ?>"         class="widefat" />
        </p>
    <p>
          <label for="<?php echo $this->get_field_id('date'); ?>">Date</label><br />
          <input type="text" name="<?php echo $this->get_field_name('date'); ?>" id="<?php         echo $this->get_field_id('date'); ?>" value="<?php echo $instance['date']; ?>"         class="widefat" />
        </p>
    <p>
          <label for="<?php echo $this->get_field_id('role'); ?>">Role</label><br />
          <input type="text" name="<?php echo $this->get_field_name('role'); ?>" id="<?php         echo $this->get_field_id('role'); ?>" value="<?php echo $instance['role']; ?>"         class="widefat" />
        </p>
    <p>
          <label for="<?php echo $this->get_field_id('imdb'); ?>">IMDB URL</label><br />
          <input type="url" name="<?php echo $this->get_field_name('imdb'); ?>" id="<?php echo         $this->get_field_id('imdb'); ?>" value="<?php echo $instance['imdb']; ?>" class="widefat"         />
        </p>
    <p>
          <label for="<?php echo $this->get_field_id('official'); ?>">Official Site         URL</label><br />
          <input type="url" name="<?php echo $this->get_field_name('official'); ?>" id="<?php         echo $this->get_field_id('official'); ?>" value="<?php echo $instance['official']; ?>"         class="widefat" />
        </p>
    <p>
          <label for="<?php echo $this->get_field_id('gallery'); ?>">Gallery URL</label><br />
          <input type="url" name="<?php echo $this->get_field_name('gallery'); ?>" id="<?php         echo $this->get_field_id('gallery'); ?>" value="<?php echo $instance['gallery']; ?>"         class="widefat" />
        </p>
    <p>
          <label for="<?php echo $this->get_field_id('summary'); ?>">Project         Summary</label><br />
          <input type="text" name="<?php echo $this->get_field_name('summary'); ?>" id="<?php         echo $this->get_field_id('summary'); ?>" value="<?php echo $instance['summary']; ?>"         class="widefat" />
        </p>
    <p>
          <label for="<?php echo $this->get_field_id('image_uri'); ?>">Image</label><br />
          <input type="text" class="img" name="<?php echo $this->get_field_name('image_uri');         ?>" id="<?php echo $this->get_field_id('image_uri'); ?>" value="<?php echo         $instance['image_uri']; ?>" />
          <input type="button" class="select-img" value="Select Image" />
        </p>
        <?php
      }


    } 
    // end class

    // register
    add_action( 'widgets_init', create_function('', 'return         register_widget("Current_Projects");') );

    // js
    function cp_enqueue()
    {
      wp_enqueue_style('thickbox');
      wp_enqueue_script('media-upload');
      wp_enqueue_script('thickbox');
      // script
      wp_enqueue_script('cp', '/wp-content/plugins/current-projects/script.js', null, null,         true);
    }
    add_action('admin_enqueue_scripts', 'cp_enqueue');
4

0 に答える 0