2013-05-19 74 views
0

在我的主題functions.php文件,我有如何在php中添加add_image_size縮略圖百分比?

add_image_size('ad-medium', $width = 250, $height = 250, true); 

這就決定了WordPress的創建「廣告媒體」縮略圖的大小。此代碼的任何更改都會確定網站上顯示的內容。

所以,如果我將250更改爲100,寬度將減少到100px。不幸的是,這有三個問題:

  1. 這改變了所有未來上傳調整大小的廣告媒體的尺寸,所以這是不可能的。
  2. 高度被忽略 - 我無法扭曲它 - 無論如何它都保持1:1的寬高比。
  3. 我無法寫100%。百分比符號不被理解。

在上下文中,代碼爲:

<?php 
} 


// activate theme support items 
if (function_exists('add_theme_support')) { // added in 2.9 

    // this theme uses post thumbnails 
    add_theme_support('post-thumbnails', array('post', 'page')); 
    set_post_thumbnail_size(100, 100); // normal post thumbnails 

    // add default posts and comments RSS feed links to head 
    add_theme_support('automatic-feed-links'); 
} 

// setup different image sizes 
if (function_exists('add_image_size')) { 
    add_image_size('blog-thumbnail', 150, 150); // blog post thumbnail size, box crop mode 
    add_image_size('sidebar-thumbnail', 140, 140, true); // sidebar blog thumbnail size, box crop mode 

    // create special sizes for the ads 
    add_image_size('ad-thumb', 75, 75, true); 
    add_image_size('ad-small', 100, 100, true); 
    add_image_size('ad-medium', $width = 250, $height = 250, true); 
    //add_image_size('ad-large', 500, 500); 
} 

// Set the content width based on the theme's design and stylesheet. 
// Used to set the width of images and content. Should be equal to the width the theme 
// is designed for, generally via the style.css stylesheet. 
if (!isset($content_width)) 
    $content_width = 500; 


// This theme supports native menu options, and uses wp_nav_menu() in one location for top navigation. 
function appthemes_register_menus() { 
    register_nav_menus(array(
     'primary' => __('Primary Navigation', 'appthemes'), 
     'secondary' => __('Footer Navigation', 'appthemes'), 
     'theme_dashboard' => __('Theme Dashboard', 'appthemes') 
    )); 
} 
add_action('init', 'appthemes_register_menus'); 

//ajax header javascript builder for child categories AJAX dropdown builder 
function cp_ajax_addnew_js_header() { 
    global $app_abbr; 
    $parentPosting = get_option($app_abbr.'_ad_parent_posting'); 
    // Define custom JavaScript function 
?> 

我怎麼能獨自離開縮略圖大小調整功能,並添加另一行代碼,將其調整到100%的寬度100%的高度?目前,除了頑固的縮略圖之外,整個頁面都在調整大小。

請讓我知道該怎麼做。

謝謝。

回答

0

請參閱:http://codex.wordpress.org/Post_Thumbnails:發佈縮略圖給予類「wp-post-image」。他們還根據正在顯示的縮略圖的大小獲得一個類您可以使用這些CSS選擇器來設置輸出的樣式。

所以,你可以添加到您的主題css文件:

#content img.ad-medium {height:100%; Width:100%;} 
+0

感謝您的答覆。我最終不得不編輯wp-includes/media.php文件。這是一個根的wordpress文件: –

+0

$ default_attr =陣列( \t \t \t 'SRC' \t => $ SRC, \t \t \t '類' \t => 「attachment- $大小」, \t \t \t 'ALT' \t => trim(strip_tags(get_post_meta($ attachment_id,'_wp_attachment_image_alt',true))),//先使用Alt字段, \t \t \t'style'=>「width:100%; max-width:100%; height:auto;「//添加此行 \t \t); \t \t如果(空($ default_attr [ 'ALT'])) \t \t \t $ default_attr [ 'ALT'] =修剪(用strip_tags($ attachment-> post_excerpt)); //如果沒有,使用標題 \t \t如果(空($ default_attr [ 'ALT'])) \t \t \t $ default_attr [ 'ALT'] =修剪(用strip_tags($ attachment-> POST_TITLE)); //最後,使用標題 –