导航菜单
首页 > 游戏中心 » 正文

制作widget小工具制作

?phpadd_action('widgets_init', 'widgetaplayerInit'); function widgetaplayerInit() { register_widget('widgetaplayer');} class widgetaplayer extends WP_Widget { /**  * widgetProfile setup  */ function widgetaplayer() { $widget_ops = array('classname' = 'widget-aplayer', 'description' = '添加Aplayer播放器'); // init widgetProfile parent::__construct('widget-aplayer', "Aplayer播放器", $widget_ops); } /**  * How to display the widgetProfile on the screen.  */ function widget( $args, $instance ) { extract( $args ); /* Our variables from the widget settings. */ $title = apply_filters('widget_name', $instance['title'] ); $type = $instance['type']; $gs = $instance['gs']; $auto = $instance['auto']; $auto = $instance['auto']; $url = $instance['url']; $pic = $instance['pic']; $word = $instance['word']; echo $before_widget; echo $this- showWidget($title,$type,$gs, $auto, $url, $pic,$word); echo $after_widget; } /**  * Update the widget settings.  */ function update( $new_instance, $old_instance ) { $instance = $old_instance; /* Strip tags for title and name to remove HTML (important for text inputs). */ $instance['title'] = strip_tags( $new_instance['title'] ); $instance['type'] = strip_tags( $new_instance['type'] ); $instance['gs'] = strip_tags( $new_instance['gs'] ); $instance['auto'] = strip_tags( $new_instance['auto'] ); $instance['url'] = strip_tags( $new_instance['url'] ); $instance['pic'] = strip_tags( $new_instance['pic'] ); $instance['word'] = strip_tags( $new_instance['word'] ); return $instance; } /**  * Displays the widget settings controls on the widget panel.  * Make use of the get_field_id() and get_field_name() function  * when creating your form elements. This handles the confusing stuff.  */ function form( $instance ) { /* Set up some default widget settings. */ $defaults = array( 'title' = '', 'type' = 'true', 'gs' = 'true', 'auto' = '', 'url'  = '', 'pic'  = '', 'word' = '' ); $instance = wp_parse_args( (array) $instance, $defaults ); ?   !-- widget title: --   p   label for=" ?php echo $this- get_field_id( 'title' ); ? " 显示标题 /label   input type="text" id=" ?php echo $this- get_field_id( 'title' ); ? " name=" ?php echo $this- get_field_name( 'title' ); ? " value=" ?php echo $instance['title']; ? " /   /p   p   label for=" ?php echo $this- get_field_id( 'type' ); ? " 自动播放 /label   select id=" ?php echo $this- get_field_id( 'type' ); ? " name=" ?php echo $this- get_field_name( 'type' ); ? "   option value="true" ?php if ( 'true' == $instance['type'] ) echo 'selected="selected"'; ? 开启 /option   option value="false" ?php if ( 'false' == $instance['type'] ) echo 'selected="selected"'; ? 关闭 /option   /select   /p   p   label for=" ?php echo $this- get_field_id( 'gs' );? " 开启歌词 /label   select id=" ?php echo $this- get_field_id( 'gs' ); ? " name=" ?php echo $this- get_field_name( 'gs' ); ? "   option value="true" ?php if ( 'true' == $instance['gs'] ) echo 'selected="selected"'; ? 开启 /option   option value="false" ?php if ( 'false' == $instance['gs'] ) echo 'selected="selected"'; ? 关闭 /option   /select   /p   p   label for=" ?php echo $this- get_field_id( 'auto' ); ? " 歌唱者 /label   input type="text" id=" ?php echo $this- get_field_id( 'auto' ); ? " name=" ?php echo $this- get_field_name( 'auto' ); ? " value=" ?php echo $instance['auto']; ? " /   /p   p   label for=" ?php echo $this- get_field_id( 'url' ); ? " 歌曲URL /label   input type="text" id=" ?php echo $this- get_field_id( 'url' ); ? " name=" ?php echo $this- get_field_name( 'url' ); ? " value=" ?php echo $instance['url']; ? " /   /p   p   label for=" ?php echo $this- get_field_id( 'pic' ); ? " 歌曲封面 /label   input type="text" id=" ?php echo $this- get_field_id( 'pic' ); ? " name=" ?php echo $this- get_field_name( 'pic' ); ? " value=" ?php echo $instance['pic']; ? " /   /p   p   label for=" ?php echo $this- get_field_id( 'word' ); ? " 歌词 /label   input type="text" id=" ?php echo $this- get_field_id( 'word' ); ? " name=" ?php echo $this- get_field_name( 'word' ); ? " value=" ?php echo $instance['word']; ? " /   /p   ?php } function showWidget($title,$type,$gs, $auto, $url, $pic, $word) { ?   link href=" ?php echo get_template_directory_uri().'/aplayer/APlayer.min.css'? " rel="stylesheet"   script src=" ?php echo get_template_directory_uri().'/aplayer/APlayer.min.js'? " /script   div ?php echo $title ? /div   div id="player1"   pre   ?php echo $word ?   /pre   /div   script  var ap = new APlayer ({ element: document.getElementById('player1'), narrow: false, autoplay: ?php echo $type ? , showlrc: ?php echo $gs ? , music: { title: ' ?php echo $title ? ', author: ' ?php echo $auto ? ', url: ' ?php echo $url ? ', pic: ' ?php echo $pic ? ' } }); ap.init();  /script   ?php }}?
收藏此文 赞一个 ( ) 打赏本站

如果本文对你有所帮助请打赏本站

  • 打赏方法如下:
  • 支付宝打赏
    支付宝扫描打赏
    微信打赏
    微信扫描打赏

相关推荐:

留言与评论(共有 0 条评论)
   
验证码:
二维码