我们经常会看到一些网站上漂亮的幻灯片展示模块,之前我们介绍过5 款WordPress推荐文章幻灯片插件 ,而本文里面,则通过详细的教程告诉你如何为你的博客添加一个基于SmoothGallery 2.0的幻灯片展示模块。

我们需要准备什么?

在开始之前我们需要先下载 SmoothGallery 2.0

1. 将所需文件放到合适的地方

  • 解压下载到的smoothgallery
  • 将解压得到的CSS文 件夹 复制到wordpress 目 录wp-content/themes/your_theme_name
  • scripts文件夹 复制到wp-content/themes/your_theme_name

一旦我们完成这一步,我们就有了在博客 上运行SmoothGallery的所需效果代 码文件。

2. 在header部份添加调用代码

在博客 主模板代码的Header部分添加CSS和script文件的连接,以便在博客 页面进行调用

将以下几行代码添加到主模板代码的Header部分:

<!–Css SmoothGallery–>
<link rel=”stylesheet” href=”<?php bloginfo(’template_url’); ?>/css/jd.gallery.css” type=”text/css” media=”screen”/>
<!–JS Mootools–>
<script type=”text/javascript” src=”<?php bloginfo(’template_url’); ?>/scripts/mootools.v1.11.js”></script>
<!–JS SmoothGallery–>
<script type=”text/javascript” src=”<?php bloginfo(’template_url’); ?>/scripts/jd.gallery.js”></script>

当这一步完成时,你就已经可以在博客 主题中使用SmoothGallery了。

3. 新建一个Gallery.php

在你的主题目录中新建一个文件gallery.php,这个文件会帮你生成展示gallery的html代码。

在开始这一步之前,应该认识到smoothgallery模块的结构。

<div class=”imageElement”>
<h3>Item Title</h3>
<p>Item Description</p>
<a href=”Link to Item ” title=”open image” class=”open”></a>
<img src=”Image of item” class=”full” alt=”Item Title” />
<img src=”Thumbmail of item” class=”thumbnail” alt=”thumbnail of Item Title” />
</div>
gallery.php文件包括两部分:

(1). 初始化SmoothGallery Script (JS)

(2). 为gally生成html/php代码

你可以在这里here 下 载到gallery.php需要这段代码,将代码全部保存到一个新建txt文档中,再保存为gallery.php就可以了。

<!– Initialization of SmoothGallery–>
<script type=”text/javascript”>
function startGallery() {
var myGallery = new gallery($(’myGallery’),
{timed: true});}
window.addEvent(’domready’,startGallery);
</script>
<!– Creation of the html for the gallery –>
<div class=”content”>
<div id=”myGallery”>
<!–
Get the 5 lasts posts of category which ID is 3
(to show the recent post use query_posts(’showposts=5′);)
–>
<?php query_posts(’showposts=5&cat=3′);?
<?php while (have_posts()) : the_post(); ?>
<!–get the custom fields gallery_image
(fields which contains the link to the image to show in the gallery)
–>
<?php $values = get_post_custom_values(”gallery_image”);?>
<!– Verify if you set the custom field gallery_image for the post –>
<?php if(isset($values[0]))
{?>
<!–define a gallery element–>
<div class=”imageElement”>
<!–post’s title to show for this element–>
<h3><?php the_title(); ?></h3>
<!–post’s excerpt to show for this element–>
<?php the_excerpt(); ?>
<!–Link to the full post–>
<a href=”<?php the_permalink() ?>” title=”Read more” class=”open”></a>
<!– Define the image for the gallery –>
<img src=”<?php echo $values[0]; ?>” class=”full” alt=”<?php the_title(); ?>”/>
<!– Define the thumbnail for the gallery –>
<img src=”<?php echo $values[0]; ?>” class=”thumbnail” alt=”<?php the_title(); ?>”/>
</div>
<?php }?>
<?php endwhile; ?>
</div>
</div>

4. 将gallery放到你的主题中

把<?php include (’gallery.php’); ?>放入你想添加的位置。当你完成这一步时,你的gallery就已经可以工作了。

要使你的gally运转起来,你需要在新建一个名为 gallery_image的自定义字段,字段值即为需要展示的图片链接,在wordpress 中推荐用相对地址,比如你的图片地址为 http://www.yoursite.com/wp-content/uploads/2008/08/artile,只需要填wp-content /uploads/2008/08/artile就可以了。

最后一步(不是必须):自定义gallery的具体显示效果。

打开文件wp-content/themes/your_theme_name/css/jd.gallery.css,在这里修改gallery 的宽和高。(通过修改jd.gallery.css完全对这个slideshow根据自己的主题进行个性化。^_^)

#myGallery, #myGallerySet, #flickrGallery
{
width: 590px;
height: 250px;
z-index:5;
border: 1px solid #000;
}

默认的字号对于中文太小了,可以调整slideshow下方信息栏的高度及文字的字号,只需要修改

.jdGallery .slideInfoZone(滑动信息栏高度、颜色等参数).jdGallery .slideInfoZone h2(信息栏内标题样式).jdGallery .slideInfoZone p(信息栏文本样式)

你还可以修改wp-content/themes/your_theme_name/scripts/jd.gallery.js来改变 gallery的展示效果(Smooth Gallery 提供了多种不同的显示效果,你可以根据需要进行修改)

更多定制信息请看Smooth Gallery Website

在wordpress中添加幻灯片展示相关推荐

  1. wordpress添加媒体_如何在WordPress中添加精选内容滑块

    wordpress添加媒体 Do you want to add a featured content slider like Yahoo or ESPN? Many popular sites us ...

  2. wordpress 背景_如何在WordPress中添加全屏背景图片

    wordpress 背景 Full screen background image seems to be a new design trend that is becoming fashionabl ...

  3. wordpress图像大小_如何在WordPress中添加图像积分(逐步操作)

    wordpress图像大小 Recently, some of our readers asked us about how to properly add image credits in Word ...

  4. wordpress添加媒体_如何在WordPress中添加jQuery FAQ手风琴

    wordpress添加媒体 Recently one of our users asked us if there was a way for them to add a FAQ accordion ...

  5. 如何在WordPress中添加Pinterest“ Pin It”按钮(最终指南)

    Do you want to add the Pinterest "Pin It" button in WordPress? Recently, a new traffic sou ...

  6. wordpress模板_如何在WordPress中添加漂亮的电子邮件模板

    wordpress模板 Do you want to change the appearance of emails sent by your WordPress site? By default, ...

  7. wordpress谷歌字体_如何在WordPress中添加Google Maps

    wordpress谷歌字体 You can add all kind of content into your WordPress site. At WPBeginner we have shown ...

  8. 城市简码_如何使用简码在WordPress中添加Twitter Bootstrap CSS

    城市简码 Adding CSS elements like tooltips, colorful buttons, and roll-over effects can help your conten ...

  9. 如何在WordPress中添加SEO关键词和元描述

    您是否想要在WordPress中正确添加SEO关键词(Meta Keywords)和元描述(Meta Description)? 元关键词和描述使您可以提高网站的SEO排名.这意味着您的业务会有更多的 ...

最新文章

  1. 使用第三方SDK(如微信、qq、快看、头条等),调用接口405 Method Not Allowed
  2. LeetCode简单题之寻找比目标字母大的最小字母
  3. Exception in thread http-bio-80exec-1 java.lang.OutOfMemoryError: PermGen s解决方案
  4. 2019年安徽高考最高分出炉:文科681分 理科710分
  5. SQL Server数据库损坏、检测以及简单的修复办法
  6. 每周一书《Spark与Hadoop大数据分析》分享!
  7. 领域驱动设计,让程序员心中有码(二)
  8. 10大热门人工智能开源工具(框架)
  9. 迅捷cad_迅捷功能
  10. win虚拟光驱怎么做linux,手把手教你用虚拟光驱安装windows10系统的详细步骤
  11. CSS表格和表单的样式
  12. mysql 表 日志_查看mysql的日志
  13. android屏幕测试工具,OLED屏幕纯色测试工具
  14. 寻找道路(NOIP2014)神奇之题。。
  15. 通达OA系统管理员操作手册
  16. YankNote 笔记软件比 Sublime 好用吗
  17. 国内三大PTPrivate Tracker站分析
  18. PHP留言并展示_php留言簿功能实现
  19. VS Code实现python代码语法检查、格式规范化、自动换行字数限制
  20. 4月11日 星期六

热门文章

  1. 11 FI配置-财务会计-定义分类账和货币类型的设置
  2. 日语学习-多邻国-关卡1-餐馆
  3. centos mysql rpm re_CentOS 7 RPM 安装 MySQL5.7
  4. python爬虫爬商品库存_利用Python爬虫爬取指定天猫店铺全店商品信息
  5. 如何查阅资料?(找数据集,文献...)
  6. 从双层优化视角理解对抗网络GAN
  7. shuffle理解【增加模型的泛化能力】
  8. Flink java.lang.NoClassDefFoundError: org/apache/flink/api/common/functions/FlatMapFunction
  9. JAVA 中JDK下载安装
  10. phpcms文件夹plugin调用怎么写路径 - 代码篇