2016-07-07 2 views
2

WooCommerce 미리보기 자르기 위치를 변경하려고합니다. 이 코드는 크기를 변경하는 데 도움이 될 수 있습니다 발견WooCommerce 축소판 자르기 위치를 변경하는 방법?

add_action('init', 'yourtheme_woocommerce_image_dimensions', 1); 

/** 
* Define image sizes 
*/ 
function yourtheme_woocommerce_image_dimensions() { 
    $catalog = array(
     'width'  => '100', // px 
     'height' => '100', // px 
     'crop'  => 0 
    ); 

    // Image sizes 
    update_option('shop_catalog_image_size', $catalog);  // Product category thumbs 
} 

내가 약간의 변화 작물 0array("center", "bottom") 같은 노력 않았다을하지만 그것은 작동하지 않습니다 :이

function yourtheme_woocommerce_image_dimensions() { 
    $catalog = array(
    'width' => '300', // px 
    'height' => '400', // px 
    'crop' => 'array("center", "bottom")' 
); 

    // Image sizes 
    update_option('shop_catalog_image_size', $catalog);  // Product category thumbs 
} 

그리고를 성공하지 :

if (function_exists('add_image_size')){ 
    add_image_size('shop_catalog', 300, 400, array('center', 'bottom')); 
} 

어쨌든 변경할 수 있습니까?

감사합니다.

답변

2

활성 어린이 테마 또는 테마 내에서 기존 이미지 크기 (자르기 옵션)를 변경하려면 'after_switch_theme' WordPress 후크를 사용해야합니다.

WordPress 3.9 이상으로 많은 새로운 기능 중 하나 인 WordPress에 업로드 된 이미지의 자르기 위치를 제어하는 ​​기능이 추가되었습니다.
woocommerce 이미지 크기에 자르기 묘약 고급 옵션을 사용할 수 있는지 여부를 알 수 없으므로 테스트해야합니다. 작물의 위치에 대한

사용할 수있는 옵션은 다음과 같습니다 그래서로 WooThemes와 워드 프레스 (이 새로운 상대) 작물 옵션에서 this snippet에 따라

left top 
left center 
left bottom 
right top 
right center 
right bottom 
center top 
center center 
center bottom 

, 당신이 시도 할 수 있습니다 :

function yourtheme_woocommerce_image_dimensions() { 
    global $pagenow; 

    if (! isset($_GET['activated']) || $pagenow != 'themes.php') { 
     return; 
    } 
    $catalog = array(
     'width'  => '300', // px 
     'height' => '400', // px 
     'crop'  => array('center', 'bottom') // New crop options to try. 
    ); 
    /* $single = array(
     'width'  => '600', // px 
     'height' => '600', // px 
     'crop'  => 1  // true 
    ); 
    $thumbnail = array(
     'width'  => '120', // px 
     'height' => '120', // px 
     'crop'  => 0  // false 
    ); */ 
    // Image sizes 
    update_option('shop_catalog_image_size', $catalog);  // Product category thumbs 
    /* update_option('shop_single_image_size', $single);  // Single product image 
    update_option('shop_thumbnail_image_size', $thumbnail); // Image gallery thumbs */ 
} 
add_action('after_switch_theme', 'yourtheme_woocommerce_image_dimensions', 1); 

이 코드 스 니펫을 활성 자식 테마 또는 테마의 function.php 파일에 붙여 넣어야합니다.

필요에 따라 코드를 주석 처리/주석 처리 제거하거나 일부분을 제거 할 수 있습니다. 이 코드는 WooCommerce 설정> 제품> 디스플레이 (제품 이미지)의 정의 옵션을 덮어 씁니다.

활성화 : 당신은 다른 활성 테마을 전환 한 후 정품 인증을 다시 전환 해야합니다
.

참고 : 그것은 완벽하게 작동하고

+0

. 감사! –

관련 문제