2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

サムネイルがlightbox系のプラグインで拡大されない時に

Posted at

状況

 Easy Fancyboxなどのプラグインを入れても、ちゃんと拡大されない。困った。

原因

 サムネイルの出力を単純化し過ぎている可能性がある。例えば、以下のような書き方。

example-before.php
  <?php the_post_thumbnail('large'); ?>

 これでは、タグ内の属性を細かく指定できない。

解決策

 とりあえず、出力することをやめて、画像へのパスを変数として取得することを考える。このために、the_post_thumbnail関数の使用から、get_post_thumbnail_id関数の使用に変更する。
 変数として取得した後は、それぞれの必要な所で出力すればいい。下の例では、jQueryプラグインのlightboxに合わせた書き方をしている。
 ちなみに、jQueryプラグインではなく、WordPressプラグインのEasy Fancyboxをする際に、data-lightbox=""を取り除いてしまうと、上手く表示されないという現象が起こった。Easy Fancyboxは、Lightboxの対抗馬であるFancyboxに依存しているはずなのだが…。

example-after.php
  <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?>
  <a href="<?php echo $image[0]; ?>" data-lightbox="<?php echo $image[0]; ?>" title="<?php the_title(); ?>">
  <img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" />
  </a>

参考

jquery - Open div inside a custom post-type with Fancybox - WordPress Development Stack Exchange

Lightbox

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?