我如何使add_image_size缩略图百分比在php


How do I make add_image_size thumbnails percentages in php?

在我的theme-functions.php文件中,我有

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

这决定了Wordpress创建'ad-medium'缩略图的大小。对这段代码的任何修改都会立即决定在网站上显示的内容。

如果我将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%高度?目前,整个页面都在调整大小,除了顽固的缩略图。

请告诉我该怎么做。

谢谢。

参见:http://codex.wordpress.org/Post_Thumbnails:缩略图被赋予一个类"wp-post-image"。它们还会根据显示的缩略图的大小获得一个类。您可以使用这些CSS选择器来设置输出的样式。

所以你可以添加到你的主题css文件:

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