function.php 搜索add_filter( ‘wp_page_menu_args’, ‘tux_page_menu_args’ );

后台添加幻灯片部件

在下边添加

 

register_sidebar(array(
    'name' => '幻灯片',
    'before_widget' => '<div class="widget %2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
));

在sidebar.php页面添加,用来调用部件

<!--边栏小工具1-->
<aside id="sidebar">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('幻灯片') ) : ?><?php endif; ?>
</aside>
<!--注:小工具名称必须要与函数文件里设置的名称一样-->

在 function.php 添加 用来调用小部件 include (‘inc/theme-widgets.php’);

在 theme-widgets.php 文件在添加,调用小工具文件

<?php
//Tux widget
include(TEMPLATEPATH . '/widget/huandengpian.php');
?>

创建小工具 huandengpian.php 以下代码

<?php
add_action('widgets_init', 'huandengpians');
function huandengpians() {
    register_widget('huandengpian');
}
class huandengpian extends WP_Widget {
    function __construct() {
        $widget_ops = array(
            'classname' => 'huandengpian',
            'description' => '显示一个文本特别推荐'
        );
        $this->WP_Widget('huandengpian', '幻灯片', $widget_ops);
    }
    
     
    
    
    function form($instance) {  
         // 给小工具(widget) 添加表单内容
         $nav1_link = $instance['nav1_link'];
         $nav1_title = $instance['nav1_title'];
         $nav1_link = $instance['nav1_link'];

         $nav2_link = $instance['nav2_link'];
         $nav2_title = $instance['nav2_title'];
         $nav2_link = $instance['nav2_link'];
 
         $nav3_link = $instance['nav3_link'];
         $nav3_title = $instance['nav3_title'];
         $nav3_link = $instance['nav3_link'];
 
         $nav4_link = $instance['nav4_link'];
         $nav4_title = $instance['nav4_title'];
         $nav4_link = $instance['nav4_link'];
         
         $nav5_link = $instance['nav5_link'];
         $nav5_title = $instance['nav5_title'];
         $nav5_link = $instance['nav5_link'];
 
         ?>
          <label>
            <h4>幻灯片1</h4>
            <input type="text" id="<?php echo $this->get_field_id('nav1_link'); ?>" name="<?php echo $this->get_field_name('nav1_link'); ?>" value="<?php echo esc_attr($nav1_link); ?>"/><span>*图1 链接</span>
             <input type="text" id="<?php echo $this->get_field_id('nav1_title'); ?>" name="<?php echo $this->get_field_name('nav1_title'); ?>" value="<?php echo esc_attr($nav1_title); ?>"/><span>*图1 链接</span>
             <input type="text" id="<?php echo $this->get_field_id('nav1_link'); ?>" name="<?php echo $this->get_field_name('nav1_link'); ?>" value="<?php echo esc_attr($nav1_link); ?>"/><span>*图1 链接</span>
          </label>
 
          <label>
            <h4>幻灯片2</h4>
            <input type="text" id="<?php echo $this->get_field_id('nav2_link'); ?>" name="<?php echo $this->get_field_name('nav2_link'); ?>" value="<?php echo esc_attr($nav2_link); ?>"/><span>*图1 链接</span>
            <input type="text" id="<?php echo $this->get_field_id('nav2_title'); ?>" name="<?php echo $this->get_field_name('nav2_title'); ?>" value="<?php echo esc_attr($nav2_title); ?>"/><span>*图1 链接</span>
             <input type="text" id="<?php echo $this->get_field_id('nav2_link'); ?>" name="<?php echo $this->get_field_name('nav2_link'); ?>" value="<?php echo esc_attr($nav2_link); ?>"/><span>*图1 链接</span>
          </label>
 
          <label>
            <h4>幻灯片3</h4>
            <input type="text" id="<?php echo $this->get_field_id('nav3_link'); ?>" name="<?php echo $this->get_field_name('nav3_link'); ?>" value="<?php echo esc_attr($nav3_link); ?>"/><span>*图1 链接</span>
            <input type="text" id="<?php echo $this->get_field_id('nav3_title'); ?>" name="<?php echo $this->get_field_name('nav3_title'); ?>" value="<?php echo esc_attr($nav3_title); ?>"/><span>*图1 链接</span>
             <input type="text" id="<?php echo $this->get_field_id('nav3_link'); ?>" name="<?php echo $this->get_field_name('nav3_link'); ?>" value="<?php echo esc_attr($nav3_link); ?>"/><span>*图1 链接</span>
          </label>
 
          <label>
            <h4>幻灯片4</h4>
            <input type="text" id="<?php echo $this->get_field_id('nav4_link'); ?>" name="<?php echo $this->get_field_name('nav4_link'); ?>" value="<?php echo esc_attr($nav4_link); ?>"/><span>*图1 链接</span>
             <input type="text" id="<?php echo $this->get_field_id('nav4_title'); ?>" name="<?php echo $this->get_field_name('nav4_title'); ?>" value="<?php echo esc_attr($nav4_title); ?>"/><span>*图1 链接</span>
             <input type="text" id="<?php echo $this->get_field_id('nav4_link'); ?>" name="<?php echo $this->get_field_name('nav4_link'); ?>" value="<?php echo esc_attr($nav4_link); ?>"/><span>*图1 链接</span>
          </label>
          
          <label>
            <h4>幻灯片5</h4>
            <input type="text" id="<?php echo $this->get_field_id('nav5_link'); ?>" name="<?php echo $this->get_field_name('nav5_link'); ?>" value="<?php echo esc_attr($nav5_link); ?>"/><span>*图1 链接</span>
             <input type="text" id="<?php echo $this->get_field_id('nav5_title'); ?>" name="<?php echo $this->get_field_name('nav5_title'); ?>" value="<?php echo esc_attr($nav5_title); ?>"/><span>*图1 链接</span>
             <input type="text" id="<?php echo $this->get_field_id('nav5_link'); ?>" name="<?php echo $this->get_field_name('nav5_link'); ?>" value="<?php echo esc_attr($nav5_link); ?>"/><span>*图1 链接</span>
          </label>
 
          <?php wp_enqueue_media(); ?>
          <script>   
          jQuery(document).ready(function(){   
          var ashu_upload_frame;   
          var value_id;   
          jQuery('.ashu_upload_button').live('click',function(event){   
              value_id =jQuery( this ).attr('id');       
              event.preventDefault();   
              if( ashu_upload_frame ){   
                  ashu_upload_frame.open();   
                  return;   
              }   
              ashu_upload_frame = wp.media({   
                  title: 'Insert image',   
                  button: {   
                      text: 'Insert',   
                  },   
                  multiple: false   
              });   
              ashu_upload_frame.on('select',function(){   
                  attachment = ashu_upload_frame.state().get('selection').first().toJSON();   
                  //jQuery('#'+value_id+'_input').val(attachment.url).trigger('change');   
                  jQuery('input[name='+value_id+']').val(attachment.url).trigger('change');   
              });   
                 
              ashu_upload_frame.open();   
          });   
          });   
          </script>
          <?php
 
 
    }  
    function update($new_instance, $old_instance) {  
         // 进行更新保存  
        $instance = $old_instance;
        $instance[ 'nav1_link' ] = strip_tags( $new_instance[ 'nav1_link' ] );
        $instance[ 'nav1_title' ] = strip_tags( $new_instance[ 'nav1_title' ] );
        $instance[ 'nav1_link' ] = strip_tags( $new_instance[ 'nav1_link' ] );
 
        $instance[ 'nav2_link' ] = strip_tags( $new_instance[ 'nav2_link' ] );
        $instance[ 'nav2_title' ] = strip_tags( $new_instance[ 'nav2_title' ] );
        $instance[ 'nav2_link' ] = strip_tags( $new_instance[ 'nav2_link' ] );
 
        $instance[ 'nav3_link' ] = strip_tags( $new_instance[ 'nav3_link' ] );
        $instance[ 'nav3_title' ] = strip_tags( $new_instance[ 'nav3_title' ] );
        $instance[ 'nav3_link' ] = strip_tags( $new_instance[ 'nav3_link' ] );
 
        $instance[ 'nav4_link' ] = strip_tags( $new_instance[ 'nav4_link' ] );
        $instance[ 'nav4_title' ] = strip_tags( $new_instance[ 'nav4_title' ] );
        $instance[ 'nav4_link' ] = strip_tags( $new_instance[ 'nav4_link' ] );
        
        
        $instance[ 'nav5_link' ] = strip_tags( $new_instance[ 'nav5_link' ] );
        $instance[ 'nav5_title' ] = strip_tags( $new_instance[ 'nav5_title' ] );
        $instance[ 'nav5_link' ] = strip_tags( $new_instance[ 'nav5_link' ] );
        return $instance;  
    }
 
    function widget($args, $instance) {  
        // 输出显示在页面上  
         $nav1_link = $instance['nav1_link'];
         $nav1_title = $instance['nav1_title'];
         $nav1_link = $instance['nav1_link'];
 
         $nav2_link = $instance['nav2_link'];
         $nav2_title = $instance['nav2_title'];
         $nav2_link = $instance['nav2_link'];
 
         $nav3_link = $instance['nav3_link'];
         $nav3_title = $instance['nav3_title'];
         $nav3_link = $instance['nav3_link'];
 
         $nav4_link = $instance['nav4_link'];
         $nav4_title = $instance['nav4_title'];
         $nav4_link = $instance['nav4_link'];
         
         $nav5_link = $instance['nav5_link'];
         $nav5_title = $instance['nav5_title'];
         $nav5_link = $instance['nav5_link'];
 
        ?>
        <div id="zSlider" >
        	<div id="picshow">
        		<div id="picshow_img">
          			<ul>
          				<li style="display: list-item;"><a href="<?php%20echo%20$nav1_link;?>" target="_blank"><img src="<?php%20echo%20$nav1_link;?>" alt="<?php echo $nav1_title;?>"></a></li>
          				<li style="display: list-item;"><a href="<?php%20echo%20$nav2_link;?>" target="_blank"><img src="<?php%20echo%20$nav2_link;?>" alt="<?php echo $nav2_title;?>"></a></li>
          				<li style="display: list-item;"><a href="<?php%20echo%20$nav3_link;?>" target="_blank"><img src="<?php%20echo%20$nav3_link;?>" alt="<?php echo $nav3_title;?>"></a></li>
          				<li style="display: list-item;"><a href="<?php%20echo%20$nav4_link;?>" target="_blank"><img src="<?php%20echo%20$nav4_link;?>" alt="<?php echo $nav4_title;?>"></a></li>
          				<li style="display: list-item;"><a href="<?php%20echo%20$nav5_link;?>" target="_blank"><img src="<?php%20echo%20$nav5_link;?>" alt="<?php echo $nav5_title;?>"></a></li>
          			</ul>
          		</div>
          	</div>
          	<div id="select_btn">
          		<ul>
          			<li class="current"></li><li class=""></li><li class=""></li><li class=""></li>
          		</ul>
          	</div>
            <div class="focus-bg-title">
            	<div id="focus-left" class="arrow-left" οnmοuseοver="IFocuse(this,true)" οnmοuseοut="IFocuse(this,false)"></div>
            	<div id="focus-center" class="focus-title">
            		<div style="float:left;width:580px;padding-left:10px;font-size:18px;" id="focus-tl-s"></div>
            		<div style="float:right;width:200px;"></div>
            	</div>
            	<div id="focus-right" class="arrow-right"></div>
            </div>
        </div>
        <?php
    }  
    
}?>

 

发表评论

共有 0 条评论