# WordPressで独自のギャラリーを作る

- リンク: https://torounit.com/blog/wordpress%e3%81%a7%e7%8b%ac%e8%87%aa%e3%81%ae%e3%82%ae%e3%83%a3%e3%83%a9%e3%83%aa%e3%83%bc%e3%82%92%e4%bd%9c%e3%82%8b/
- 公開日: 2010-09-24T11:29:18+09:00
- 作成者: Toro\_Unit

先日、[Free Division](http://www.freedivision.info)のサイトのリニューアルを行いま
した。
 そこで、ギャラリーみたいなのを作ったのですが、標準のgallery機能がちょっと
使いづらかったので、独自で作成しました。  [php] function get_gallery($size = ‘thumbnail’,
$linkSize = ‘large’){ $attachments = get_children(array(‘post_parent’ => get_the_ID(),’
post_type’ => ‘attachment’,’post_mime_type’ => ‘image’,’orderby’ => ‘date’));//添付
ファイルのデータ呼び出し。 $lim = count($attachments); echo "<ul class=’gallery’
>\n"; for($i=0; $i<$lim; $i++){ $attachmentData = array_pop($attachments); $img 
= wp_get_attachment_image_src($attachmentData ->ID,$size); $linkImg = wp_get_attachment_image_src(
$attachmentData ->ID,$linkSize); echo "<li class=’imgbox colorbox-".$attachmentData-
>ID."’><a href=".$linkImg[0]." title=".$attachmentData ->post_title."><img src=".
$img[0]."></a></li>\n"; } echo "</ul>\n"; } [/php]

後はadd_shortcodeとかでショートコード化するなり、テンプレートで呼び出すなり。

これに、[jQuery Lightbox For Native Galleries](http://wordpress.org/extend/plugins/jquery-lightbox-for-native-galleries/)
等を組み合わせると、それだけで[こんなギャラリー](http://www.freedivision.info/document/)
が作成されます。
