Like Boxをウィジェットに追加する。
» Like Box – Facebook開発者
<?php
/**
* Add Facebook Like Box
* 1. display following facebook like box code
* <pre>
* <div id="fb-root"></div>
* </pre>
*
* 2. invoke script
* </pre>
* <script>( function( d, s, id ) {
* statements
* }( document, 'script', 'facebook-jssdk' ));</script>
* </pre>
*
* 3. display like box to fb_link_box
* <pre>
* <div class="fb-like-box" data-href="" data-width="292" data-height="300" data-show-faces="true" data-stream="false" data-header="true"></div>
* </pre>
*
* @author Sawai Hiroshi
*/
class Facebook_Like_Box extends WP_Widget
{
/** constructor */
function __construct()
{
parent::WP_Widget( false, $name = 'Facebook_Like_Box' );
}
/**
* echo the Facebook like page code
*
* @param array $args
* received form WordPress System
* @param WP_Widget $instance
* received from widget form
*/
function widget( $args, $instance )
{
extract( $args, EXTR_SKIP);
$fb_root = empty( $instance[ 'fb_root' ] ) ? ' ' : apply_filters( 'widget_root', $instance[ 'fb_root' ] );
$script = empty( $instance[ 'script' ] ) ? ' ' : apply_filters( 'widget_script', $instance[ 'script' ] );
$fb_link_box = empty( $instance[ 'fb_link_box' ] ) ? ' ' : apply_filters( 'widget_fb_link_box', $instance[ 'fb_link_box' ] );
if ( isset( $fb_root ) === true && $fb_root !== '' ) {
echo $fb_root;
}
if ( isset( $script ) === true && $script !== '' ) {
echo $script;
}
/** @var $before_widget form WP_Widget */
echo $before_widget;
if ( isset( $fb_link_box ) === true && $fb_link_box !== '' ) {
echo $fb_link_box;
}
/** @var $after_widget from WP_Widget */
echo $after_widget;
}
/**
* update the widget
*
* @param object $new_instance
* received form WordPress System
* @param object $old_instance
* received form WordPress System
* @return object
*/
function update( $new_instance, $old_instance )
{
return $new_instance;
}
/**
* widget form
*
* @param object $instance new instance
* received form WordPress System
* @return string|void
*/
function form( $instance )
{
$fb_root = empty( $instance[ 'fb_root' ] ) ? ' ' : apply_filters( 'widget_root', $instance[ 'fb_root' ] );
$script = empty( $instance[ 'script' ] ) ? ' ' : apply_filters( 'widget_script', $instance[ 'script' ] );
$fb_link_box = empty( $instance[ 'fb_link_box' ] ) ? ' ' : apply_filters( 'widget_fb_link_box', $instance[ 'fb_link_box' ] );
?>
<div>
<label for="<?php echo esc_attr( $this->get_field_id( 'fb_root' ) ); ?>">fb_root :
<textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'fb_root' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'fb_root' ) ); ?>"><?php echo esc_html( $fb_root ); ?></textarea>
</label>
</div>
<div>
<label for="<?php echo esc_attr( $this->get_field_id( 'script' ) ); ?>">script :
<textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'script' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'script' ) ); ?>"><?php echo $script; ?></textarea>
</label>
</div>
<div>
<label for="<?php echo esc_attr( $this->get_field_id( 'fb_link_box' ) ); ?>">fb link box :
<textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'fb_link_box' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'fb_link_box' ) ); ?>"><?php echo esc_html( $fb_link_box ); ?></textarea>
</label>
</div>
<?php
}
}
register_widget( 'Facebook_Like_Box' );
No comments yet.
改行と段落タグは自動で挿入されます。
メールアドレスは表示されません。