2013-02-01 2 views
1

누구나 사각형 WordPress의 미리보기 이미지를 얻는 방법을 알고 있습니까? 나는이를 사용하는 경우큰 사각형 WordPress의 축소판 미리보기

는 이미지가

<?php the_post_thumbnail(array(205,205)); ?> 

사각형이 있습니다하지만 이렇게하면, 그들은 내가의 300 X 말을 할 수있는 썸네일 갤러리를 만들 필요가

<?php the_post_thumbnail(array(135,135)); ?> 

정사각형 300 평방 이미지.

+0

"이 이미지를 사용하면 이미지가 사각형이 아닙니다"- "this"로 무엇을 의미합니까? –

답변

5

먼저 자신의 사진 크기를 만들어야합니다. 이것은 add_image_size() 기능으로 수행됩니다.

당신은 이런 식으로 작업을 수행 할 수는 있지을 경우

if (function_exists('add_theme_support')) { 
    add_theme_support('post-thumbnails'); 
    add_image_size('square-large', 300, 300, true); // name, width, height, crop 
    add_filter('image_size_names_choose', 'my_image_sizes'); 
} 

function my_image_sizes($sizes) { 
    $addsizes = array(
     "square-large" => __("Large square image") 
    ); 
    $newsizes = array_merge($sizes, $addsizes); 
    return $newsizes; 
} 

이 테마 썸네일에 대한 지원을 추가합니다. 잘린 300x300 픽셀로 새로운 이미지 크기를 만듭니다. 두 번째 기능은 더 나은 설명을 제공하고 미디어 삽입 대화 상자에 표시되는지 확인합니다.

다음과 같이 사용할 수 있습니다.

<?php the_post_thumbnail('square-large'); ?> 

테마를 functions.php 개 줄에 추가 할 수 있습니다. 테마가 업데이트 될 때이 줄을 덮어 쓰지 않으려면 하위 테마를 만드는 것이 좋습니다 (read here how to do that).

기존 이미지에는 영향을 미치지 않습니다. 누락 된 미리보기 이미지를 다음 코드로 다시 만들 수 있습니다.

include_once(ABSPATH . 'wp-admin/includes/image.php'); 
function regenerate_all_attachment_sizes() { 
    $args = array('post_type' => 'attachment', 'numberposts' => 100, 'post_status' => null, 'post_parent' => null, 'post_mime_type' => 'image'); 
    $attachments = get_posts($args); 
    if ($attachments) { 
     foreach ($attachments as $post) { 
      $file = get_attached_file($post->ID); 
      wp_update_attachment_metadata($post->ID, wp_generate_attachment_metadata($post->ID, $file)); 
     } 
    }  
} 
regenerate_all_attachment_sizes(); 

이 코드는 한 번만 실행하면됩니다.

+0

이 권리를 갖도록하겠습니다. 이미지를 업로드 할 때 add_image_size는 나중에 사용할 수있는 300x300 크기의 미리보기 이미지를 만듭니다. 하지만 어떻게 사용합니까? 이렇게? ' ' – Ciprian

+0

답변을 업데이트했습니다. –

+0

축소판을 다시 생성하기 위해 해당 코드를 실행하려면 어떻게해야합니까? 나는 그것을 functions.php에 붙여 넣었고 서버 오류가 발생했습니다. – Ciprian

관련 문제