2014-08-27 93 views
0

我將我的html模板轉換爲WordPress。 Fancybox在我的html版本中工作正常,但不是在wordpress中。fancybox未在WordPress中加載圖片

在HTML版本中,的fancybox代碼爲:

<a href="images/p3.jpg" class="project-img fancybox"></a> 

,現在在WP版本:

<a href="<?php the_post_thumbnail(); ?>" class="project-img fancybox"></a> 

& jQuery的:

$(".fancybox").fancybox({ 

     padding  : 0, 
     margin  : 100, 
     openEffect : 'elastic', 
     closeEffect : 'elastic', 
     openSpeed : 400, 
     closeSpeed : 400, 

     helpers : { 
      overlay : { 
       css : { 
        'background' : 'rgba(0, 0, 0, 0.75)' 
       } 
      } 
     } 
    }); 

但它不工作我,當我懸停我的圖像時,它返回:

class="project-img fancybox"> 

我不是專業人士,所以找不到任何解決方案。

回答

0

使用功能get_the_post_thumbnail

您無法將the_post_thumbnail傳遞給href標記。

+0

但問題是,我有4個職位在該節和所有動態的循環產生。如果我使用get_the_post_thumbnail(),我必須使用參數($ post_id)&我不知道如何使它動態化 – 2014-08-27 09:00:12

0

您正在使用href屬性中的錯誤功能。它顯示當前帖子的精選圖片(以前稱爲帖子縮略圖),如在該帖子的編輯屏幕中設置的。該標籤必須在The Loop中使用。

使用get_the_post_thumbnail()代替:

<a href="<?php get_the_post_thumbnail($post_id, $size, $attr); ?>" class="project-img fancybox"></a>