如何在php中生成“添加图像大小”缩略图百分比?

如何在php中生成“添加图像大小”缩略图百分比?,php,resize,width,Php,Resize,Width,在我的theme-functions.php文件中,我有 add_image_size('ad-medium', $width = 250, $height = 250, true ); 这决定了Wordpress创建“广告媒体”缩略图的大小。此代码的任何更改都会立即决定网站上显示的内容 因此,如果我将250改为100,宽度将减少到100px。不幸的是,这有三个问题: 这改变了所有未来上传广告媒体的尺寸,所以这是不可能的 高度被忽略-我不能扭曲它-它保持1:1的纵横比,无论什么 我不能百分之百

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

add_image_size('ad-medium', $width = 250, $height = 250, true );
这决定了Wordpress创建“广告媒体”缩略图的大小。此代码的任何更改都会立即决定网站上显示的内容

因此,如果我将250改为100,宽度将减少到100px。不幸的是,这有三个问题:

  • 这改变了所有未来上传广告媒体的尺寸,所以这是不可能的
  • 高度被忽略-我不能扭曲它-它保持1:1的纵横比,无论什么
  • 我不能百分之百地写作。百分号不清楚
  • 在上下文中,代码是:

        <?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
    ?>
    
    请参见::Post缩略图被赋予一个类“wp Post image”。它们还根据显示的缩略图的大小获得一个类。您可以使用这些CSS选择器设置输出样式

    因此,您可以将以下内容添加到主题css文件中:

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

    谢谢你的回复。最后我不得不编辑wp includes/media.php文件。这是一个根wordpress文件:$default\u attr=array('src'=>$src,'class'=>“attachment-$size”,'alt'=>trim(strip_标签(get_post_meta($attachment_id,'u wp_attachment_image_alt',true)),//首先使用alt字段,'style'=>“宽度:100%;最大宽度:100%;高度:auto;//添加了这一行);如果(空($default_attr['alt'])$default_attr['alt']=trim(strip_tags($attachment->post_extract));//如果不是,请使用标题If(空($default_attr['alt'])$default_attr['alt']=trim(strip_tags($attachment->post_title));//最后,使用标题