How to Add WordPress 2.5 Gallery to Your Current Theme

Note: If you are a chinese user, you can get the Chinese version of this post here: 让您当前的主题支持 WordPress 2.5 的相册功能

The Great WordPress 2.5 given us so many new features. One of them is Gallery. And when you insert a gallery into a post and click a image of them, it will show 3 image on the page ("Previous image Thumbnail", "Current image", "Next image Thumbnail") insteat the "Single image" like before.

Of course, it is just to display like that in the default theme (Right now Sandbox and K2 also could do this). Because of so many reason, the theme you are using, maybe can't do that. Waiting for the Theme's Designer?? Forget it. It is so easy to do that, do it yourself.

In this post, I will make the default theme like a example.

Compare the theme between 2.3.3 and 2.5. You will find out that there was a new file "image.php". Right, this is the file to implement the effects. In this file, you can see some code like this:

<a href="<?php echo get_permalink($post->post_parent); ?>" rev="attachment"><?php echo get_the_title($post->post_parent); ?></a> » <?php the_title(); ?>

Action: Display tittles of the image and the post

Effect: Post Tittle » Attachment Tittle

<?php if ( !empty($post->post_excerpt) ) the_excerpt(); ?>

Action: Display the caption of the image

<?php the_content(); ?>

Action: Display the description of the image

<?php previous_image_link() ?>

Action: Display the thumbnail of the previous image

<?php next_image_link() ?>

Action: Display the thumbnail of the next image

Actually, the codes upper can display everything just like the default theme. But you must put theme in the "image.php" file. It was not a image.php file in your current theme folder? Don't worry. "Single.php", "attachment.php" and "image.php" were so similar. So you can choose one of theme to given a edit. But, just remember that, DO NOT edit the original file, you should make a copy of the file and rename it to "image.php". Otherwise the theme will not work fine in the previous WordPress release.

Well, almost done. Tell you a easy way to do all of those. Copy the "image.php" of the default theme to your current theme folder. And edit the CSS file or edit the "image.php" file to correct the code. These will need you have some programming ability.

I used my fucking english to wrote down this post. It maybe has so many grammar error. So if you understand what I said, and you would help me, please leave a massage and tell me the error both contents and grammar.

Thank you everybody.

Related posts

2 条引用

  1. [...] 2008-04-12更新:我用我蹩脚的英文,把该文章翻译成英文的了。点击这里可以到我的英文博客上查看,欢迎各位给提点意见,语法错误估计会很多。早知道就不写这么多了,翻译起来还能简单一些。 [...]

  2. [...] 2008-04-12更新:我用我蹩脚的英文,把该文章翻译成英文的了。点击这里查看,欢迎各位给提点意见,语法错误估计会很多。早知道就不写这么多了,翻译起来还能简单一些。 [...]

发表评论

您的电子邮箱地址永远不会被公开。 标记为 * 的区域必须填写

*
*