在之前的建站教程中,我们讲了如何制作淘宝图片放大镜功能,并给了相应的代码。这是一个固定的HTML代码,很多学习建网站的学员不懂怎么把它与Wordpress结合起来,使用动态PHP代码进行调用。
下面介绍一下Wordpress网站产品图片放大镜效果制作方法及代码。
方法/步骤
1. 图片放大镜功能JQUERY插件代码
jquery.imagezoom.min.js
2.将JQUERY插件,放在与自己网页同一个目录下;
3. 在自己网站的头部文件</head>标签上面,使用以下的JS代码来调用图片放大镜功能JQUERY插件。
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="<?php bloginfo('template_directory'); ?>/images/jquery.imagezoom.min.js"></script>
4. 在Style.css文件里添加以下的CSS样式代码,用于控制放大镜效果样式;
5. 在底部模板里放上以下的JS代码;
<script type="text/javascript">
$(document).ready(function(){
$(".jqzoom").imagezoom();
$("#thumblist li a").click(function(){
$(this).parents("li").addClass("tb-selected").siblings().removeClass("tb-selected");
$(".jqzoom").attr('src',$(this).find("img").attr("mid"));
$(".jqzoom").attr('rel',$(this).find("img").attr("big"));
});
});
</script>
6. 安装WordPress后台框架WPD主题设置面板;
<?php
//自定义面板类的实例化
/**********title*************/
$options = array();
$boxinfo = array('title' => '参数填写', 'id'=>'ashubox', 'page'=>array('post'), 'context'=>'normal', 'priority'=>'low', 'callback'=>'');
$options[] = array( "name" => "产品缩略图上传",
"type" => "title");
$options[] = array(
"name" => "缩略图1",
"desc" => "",
"id" => "ashu_upimg01",
"std" => "",
"button_label"=>'上传图片',
"type" => "media"
);
$options[] = array(
"name" => "缩略图2",
"desc" => "",
"id" => "ashu_upimg02",
"std" => "",
"button_label"=>'上传图片',
"type" => "media"
);
$options[] = array(
"name" => "缩略图3",
"desc" => "",
"id" => "ashu_upimg03",
"std" => "",
"button_label"=>'上传图片',
"type" => "media"
);
$options[] = array(
"name" => "缩略图4",
"desc" => "",
"id" => "ashu_upimg04",
"std" => "",
"button_label"=>'上传图片',
"type" => "media"
);
$options[] = array(
"name" => "缩略图5",
"desc" => "",
"id" => "ashu_upimg05",
"std" => "",
"button_label"=>'上传图片',
"type" => "media"
);
$new_box = new ashu_meta_box($options, $boxinfo);
?>
7. 在显示放大镜效果的位置使用以下的代码进行调用;
<div class="box">
<div class="tb-booth tb-pic tb-s310">
<?php if ( get_post_meta($post->ID, 'ashu_upimg01', true) ) {?>
<a href="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg01",true);?>"><img src="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg01",true);?>" rel="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg01",true);?>" class="jqzoom" /></a>
<?php }?>
</div>
<ul class="tb-thumb" id="thumblist">
<?php if ( get_post_meta($post->ID, 'ashu_upimg01', true) ) {?>
<li class="tb-selected"><div class="tb-pic tb-s40"><a href="javascript:void(0);"><img src="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg01",true);?>" mid="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg01",true);?>" big="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg01",true);?>"></a></div></li>
<?php }else{?><li class="tb-selected"><div class="tb-pic tb-s40"></div></li> <?php }?>
<?php if ( get_post_meta($post->ID, 'ashu_upimg02', true) ) {?>
<li><div class="tb-pic tb-s40"><a href="javascript:void(0);"><img src="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg02",true);?>" mid="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg02",true);?>" big="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg02",true);?>"></a></div></li>
<?php }else{?><li><div class="tb-pic tb-s40"></div></li> <?php }?>
<?php if ( get_post_meta($post->ID, 'ashu_upimg03', true) ) {?>
<li><div class="tb-pic tb-s40"><a href="javascript:void(0);"><img src="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg03",true);?>" mid="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg03",true);?>" big="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg03",true);?>"></a></div></li>
<?php }else{?><li><div class="tb-pic tb-s40"></div></li> <?php }?>
<?php if ( get_post_meta($post->ID, 'ashu_upimg04', true) ) {?>
<li><div class="tb-pic tb-s40"><a href="javascript:void(0);"><img src="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg04",true);?>" mid="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg04",true);?>" big="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg04",true);?>"></a></div></li>
<?php }?>
<?php if ( get_post_meta($post->ID, 'ashu_upimg05', true) ) {?>
<li><div class="tb-pic tb-s40"><a href="javascript:void(0);"><img src="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg05",true);?>" mid="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg05",true);?>" big="<?php%20echo%20get_post_meta($post->ID,"ashu_upimg05",true);?>"></a></div></li>
<?php }?>
</ul>
</div>
8. 这样就实现了放大镜代码与Wordpress程序的结合,制作出Wordpress网站产品图片放大镜效果。
THE END
暂无评论内容