2017-06-12 144 views
1

我用這個代碼從WordPress的帖子獲得第一圖像中的functions.php如何爲wordpress製作自定義圖片大小調整命令?

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; 
} 

它得到第一個圖像從每一個崗位和我的主題模板

<div class="imgdiv"><a href="<?php the_permalink() ?>"><img src="<?php echo catch_that_image() ?>" width="250"></a></div> 
的search.php中使用此命令

所以這是用於搜索結果:我想那wordpress做第一個圖像的確切尺寸,有沒有什麼辦法,因爲我手動上傳他們,也使用手動插入職位?

我想要的就是wordpress製作寬度爲250px,寬度爲800px的圖片。

我的網站的網址是因爲virmodrosti.com,如果你搜索短語「礦物溫泉」例如,你會得到這個頁面http://www.virmodrosti.com/?s=minerali 以下是已經使用寬度= 250,但沒有任何意義的大小的所有圖像,他們仍然是800x450。

謝謝。

下面fucntions.php代碼
+0

嘗試用add_image_size ?? https://developer.wordpress.org/reference/functions/add_image_size/ –

回答

相關問題