テーマにsandboxを使用した場合、ギャラリー機能を使用するとサムネイルからのリンクがパラメータに関わりなく「添付ファイルのページ」へのリンクになってしまいます。
これはfunctions.php内の
// Function to filter the default gallery shortcode
という箇所でgallery shortcodeをフックしているからです。
- extract(shortcode_atts( array(
‘orderby’ => ‘menu_order ASC, ID ASC’,
‘id’ => $post->ID,
‘itemtag’ => ‘dl’,
‘icontag’ => ‘dt’,
‘captiontag’ => ‘dd’,
‘columns’ => 3,
‘size’ => ‘thumbnail‘,
), $attr )); - …
- foreach ( $attachments as $id => $attachment ) {
$img_lnk = get_attachment_link($id);
$img_src = d7rwp_get_attachment_image_src( $id, $size );
$img_src = $img_src[0];
$img_alt = $attachment->post_excerpt;
if ( $img_alt == null )
$img_alt = $attachment->post_title;
$img_rel = apply_filters( ‘gallery_img_rel’, ‘attachment’ ); // Available filter: gallery_img_rel
$img_class = apply_filters( ‘gallery_img_class’, ‘gallery-image’ ); // Available filter: gallery_img_class
$output .= “\n\t” . ‘<’ . $itemtag . ‘ class=”gallery-item gallery-columns-’ . $columns .’”>’;
$output .= “\n\t\t” . ‘<’ . $icontag . ‘ class=”gallery-icon”><a href=”‘ . $img_src . ‘” title=”‘ . $img_alt . ‘” rel=”wp-lytebox’ . $img_rel . ‘”><img src=”‘ . $img_src . ‘” alt=”‘ . $img_alt . ‘” class=”‘ . $img_class . ‘ attachment-’ . $size . ‘” /></a></’ . $icontag . ‘>’;
赤字の箇所が「決め打ち」になっています。
本来は引数から条件分岐したいところですが、面倒臭いので「ファイルへのリンク」に決め打ちしてしまいます。
ついでに並び順も「降順」に変更します。
- extract(shortcode_atts( array(
‘orderby’ => ‘menu_order DESC, ID DESC‘,
‘id’ => $post->ID,
‘itemtag’ => ‘dl’,
‘icontag’ => ‘dt’,
‘captiontag’ => ‘dd’,
‘columns’ => 3,
‘size’ => ‘thumbnail’,
), $attr )); - …
- foreach ( $attachments as $id => $attachment ) {
$img_lnk = get_attachment_link($id);
$img_src = d7rwp_get_attachment_image_src( $id, $size );
$img_src = $img_src[0];
$img_src_org = d7rwp_get_attachment_image_src( $id, “full” );
$img_src_org = $img_src_org[0];
$img_alt = $attachment->post_excerpt;
if ( $img_alt == null )
$img_alt = $attachment->post_title;
$img_rel = apply_filters( ‘gallery_img_rel’, ‘attachment’ ); // Available filter: gallery_img_rel
$img_class = apply_filters( ‘gallery_img_class’, ‘gallery-image’ ); // Available filter: gallery_img_class
$output .= “\n\t” . ‘<’ . $itemtag . ‘ class=”gallery-item gallery-columns-’ . $columns .’”>’;
$output .= “\n\t\t” . ‘<’ . $icontag . ‘ class=”gallery-icon”><a href=”‘ . $img_src_org . ‘” title=”‘ . $img_alt . ‘” rel=”wp-lytebox’ . $img_rel . ‘”><img src=”‘ . $img_src . ‘” alt=”‘ . $img_alt . ‘” class=”‘ . $img_class . ‘ attachment-’ . $size . ‘” /></a></’ . $icontag . ‘>’;
これでlight-boxやwp-lyteboxが動作します。
サンプルは、gallery機能テスト2、gallery機能テストをご覧ください。

