[WordPress] ワードプレスのウィジェットを使用して html 形式で空白を埋めるため

スポンサーリンク

質問

私の最初の WP のウィジェットを構築します。(下記参照)サムネイル リンク、動画のリンク、プロジェクトのタイトルと説明を入力へのクライアント アクセスを提供する必要があります。ウィジェットは格納するデータを取得するが HTML フィールドにそのデータを送信する方法について困惑します

おかげでダン

    <?php  
/*
Plugin Name: Red Viking Video
Plugin URI: http://digital-persona.com
Description: Bla Bla Bla
Version: 1.0
Author: Dan
Author URI: Bio Page
Licence: none
*/


class WP_red_viking_video extends WP_Widget {
    function __construct() {
        parent::__construct(false, $name = __('Red Viking Video'));
        }
    function form($instance) {
        $thumbnail = esc_textarea( $instance['thumbnail'] );
        $you_tube_link = esc_textarea( $instance['you_tube_link'] );
        $project_title = esc_textarea( $instance['project_title'] );
        $project_details = esc_textarea( $instance['project_details'] );
?>

<p>
  <label for="<?php echo $this->get_field_id('thumbnail'); ?>"><?php _e('Thumbnail' ); ?></label>
  <textarea class="widefat" rows="3" cols="30" id="<?php echo $this->get_field_id('thumbnail'); ?>" name="<?php echo $this->get_field_name('thumbnail'); ?>"><?php if (!empty($thumbnail)) echo $thumbnail; ?></textarea>
<p>
  <label for="<?php echo $this->get_field_id('you_tube_link'); ?>">
    <?php _e('You Tube Link', 'wp_widget_plugin'); ?>
  </label>
  <textarea class="widefat" rows="3" cols="30" id="<?php echo $this->get_field_id('you_tube_link'); ?>" name="<?php echo $this->get_field_name('you_tube_link'); ?>"><?php if (!empty($you_tube_link)) echo $you_tube_link; ?></textarea>
</p>
<p>
  <label for="<?php echo $this->get_field_id('project_title'); ?>">
    <?php _e('Project Title', 'wp_widget_plugin'); ?>
  </label>
  <textarea class="widefat" rows="3" cols="30" id="<?php echo $this->get_field_id('project_title'); ?>" name="<?php echo $this->get_field_name('project_title'); ?>"><?php if (!empty($project_title)) echo $project_title; ?></textarea>
</p>
<p>
  <label for="<?php echo $this->get_field_id('project_details'); ?>">
    <?php _e('Project Details', 'wp_widget_plugin'); ?>
  </label>
  <textarea class="widefat" rows="10" cols="30" id="<?php echo $this->get_field_id('project_details'); ?>" name="<?php echo $this->get_field_name('project_details'); ?>"><?php if (!empty($project_details)) echo $project_details; ?></textarea>
</p>
<?php
        }
    function update($new_instance, $old_instance) {
    $instance = $old_instance;
    // Fields
    $instance['thumbnail'] = esc_textarea($new_instance['thumbnail']);
    $instance['you_tube_link'] = strip_tags($new_instance['you_tube_link']);
    $instance['project_title'] = strip_tags($new_instance['project_title']);
    $instance['project_details'] = strip_tags($new_instance['project_details']);
    return $instance;
}
    function widget($args, $instance) {
        ?>
<div class="widget featured-video one-third column project"> 

  <!-- ====================== YOU TUBE LINK ======================= --> 
  <a class="youtube" href="<?php echo $you_tube_link; ?>" title="Orchestra London Promo"> 
  <!-- ==================== END YOU TUBE LINK ===================== -->
  <div class="thumbnail slide"> 
    <!-- ===================== THUMBNAIL LINK ======================= --> 
    <img class="thumbnail" src="http://<?php echo $thumbnail; ?>" /> 
    <!-- =================== END THUMBNAIL LINK ===================== -->

    <div class="project snipit"> 
      <!-- ==================== OVERLAY CONTENT ======================= -->
      <h4><?php echo $project_title; ?></h4>
      <!-- PROJECT TITLE -->
      <p><?php echo $project_details; ?></p>
      <!-- PROJECT DESCRIPTION --> 
      <!-- ================= END OVERLAY CONTENT ===================== --> 
    </div>
  </div>
  </a> </div>
<?php 
    }
}






add_action('widgets_init', function() {
    register_widget('WP_red_viking_video');
    })
?>

の答え

彼らは、

update()

関数であると同様に、

$instance

変数に格納されます。ちょうど

widget()

関数の上に次のコードを追加:

$thumbnail       = $instance['thumbnail'];
$you_tube_link   = $instance['you_tube_link'];
$project_title   = $instance['project_title'];
$project_details = $instance['project_details'];

http://stackoverflow.com/questions/29186685/how-can-i-use-a-wordpress-widget-to-fill-in-blanks-in-html

スポンサーリンク

Leave a Reply