2010-12-22 66 views
0

我想在wordpress文章中獲取第一張圖片的路徑。我正在嘗試實現一個小的JQuery縮放效果。 $ thumbID會返回圖片的縮略圖。我想要WordPress的帖子圖像路徑

a href='http://hahadb.com/wp-content/uploads/2010/12/armor-failx640.jpg' 

指向原始附加圖像,因爲它比拇指大,這對縮放效果非常有效。目前我只有2個職位,每個職位都有一個附加的圖像。

<div class="preview"><a href='http://hahadb.com/wp-content/uploads/2010/12/armor-failx640.jpg' class = 'cloud-zoom' id='zoom1' 
      rel="adjustX: 10, adjustY:-4"><?php echo "$thumbID"; ?></a></div> 

謝謝。

+0

'$ thumbID`從哪裏來,將有助於瞭解如何提取後期圖片。 **注意:** ob_%函數與正則表達式並不是理想的解決方案。 – t31os 2010-12-22 13:38:43

回答

-2

我想通了。 :D酷派功能:

function catch_that_image() { 
    global $post, $posts; 
    $first_img = ''; 
    ob_start(); 
    ob_end_clean(); 
    $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); 
    $first_img = $matches [1] [0]; 

    if(empty($first_img)){ //Defines a default image 
    $first_img = "/images/default.jpg"; 
    } 
    return $first_img; 
}