WordPress视频模式小部件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WordPress视频模式小部件相关的知识,希望对你有一定的参考价值。
A plugin that adds widget functionality to a third-party video modal plugin. The widget accepts a YouTube video ID and a thumbnail URL of the user's choice. It then generates a thumbnail link that launches a video modal via the third-party plugin. Optionally, if the user chooses to leave the thumbnail field blank, the default YouTube video thumbnail is used as the anchor to launch the modal.
<?php /* Plugin Name: UTMOST CO. WIDGETS Description: Site specific code changes for utmostco.com */ /* Start Adding Functions Below this Line */ /* VIDEO MODAL START */ class UtmostVideoModalWidget extends WP_Widget { public function __construct() { 'classname' => 'utmost-video-modal-widget', 'description' => 'A modal that autoplays videos.' ); parent::WP_Widget('utmost-video-modal-widget', 'Utmost Video Modal', $widget_options); } /** * Outputs the content of the widget * * @param array $args * @param array $instance */ public function widget( $args, $instance ) { $videoThumbnail = (isset( $instance['videoThumbnail'] )) ? esc_attr($instance['videoThumbnail']) : ''; <a href="https://www.youtube.com/watch?v=<?php echo $videoId; ?>" rel="wp-video-lightbox"class="modal-click"> <img src="<?php echo $videoThumbnail; ?>" </a> <?php } else { ?> <a href="https://www.youtube.com/watch?v=<?php echo $videoId; ?>" style="width: 100%; height: auto; margin: 0; border: none;" rel="wp-video-lightbox"class="modal-click"> <img style="width: 100%; height: auto; margin: 0; border: none;"src="http://img.youtube.com/vi/<?php echo $videoId; ?>/mqdefault.jpg"> </a> <?php } } /** * Outputs the options form on admin * * @param array $instance The widget options */ public function form( $instance ) { ?> <div> <label style="display: block; margin-top:15px;" for="<?php echo $this->get_field_id('videoId');?>"> Video ID </label> <br /> <input style="width:100%; margin-bottom:15px;" id="<?php echo $this->get_field_id('videoId');?>" name="<?php echo $this->get_field_name('videoId');?>" value="<?php echo esc_attr($instance['videoId']); ?>" /><br> <label style="display: block; margin-bottom:15px;" for="<?php echo $this->get_field_id('videoId');?>"> Modal Thumbnail<br> Creates a text link that is clicked to launch the modal.<br> (Leave this field blank to use default YouTube thumbnail.) </label> <input style="width:100%; margin-bottom:15px;" id="<?php echo $this->get_field_id('videoThumbnail');?>" name="<?php echo $this->get_field_name('videoThumbnail');?>" value="<?php echo esc_attr($instance['videoThumbnail']); ?>" /> </div> <?php } } function utmost_video_modal_widget_init() { register_widget('UtmostVideoModalWidget'); } add_action('widgets_init', 'utmost_video_modal_widget_init'); /* VIDEO MODAL END */ /* Stop Adding Functions Below this Line */ ?>
以上是关于WordPress视频模式小部件的主要内容,如果未能解决你的问题,请参考以下文章
Wordpress:在不使用文本小部件的情况下将 html 代码添加到小部件区域