WordPress.org

Plugin Directory

Changeset 633818


Ignore:
Timestamp:
12/04/12 04:09:47 (17 months ago)
Author:
mitchoyoshitaka
Message:

+ on the fly thumbnail generation

  • user-programmable size option
Location:
yet-another-related-posts-plugin/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • yet-another-related-posts-plugin/trunk/readme.txt

    r633784 r633818  
    243243 
    244244= 4.0.1 = 
     245* Improvements to thumbnail handling 
     246    * Thumbnails of the appropriate size are generated on the fly, if they do not already exist 
     247    * Thumbnail size can be specified by adding `add_image_size( 'yarpp-thumbnail', $width, $height, true );` to your theme's `functions.php` file. In the future I may add some UI to the settings to also set this... feedback is requested on whether this is a good idea. 
     248    * Fixed a typo and simplified an item in the dynamic `styles-thumbnails.php` styles 
    245249* Bugfix: a class of `yarpp-related-` with a stray hyphen was sometimes being produced. Now fixed so it produces `yarpp-related`. 
    246250* Bugfix: some transients expired too soon if object caching was used 
  • yet-another-related-posts-plugin/trunk/styles-thumbnails.php

    r632931 r633818  
    1111    $height = (int) $_GET['height']; 
    1212if ( isset($_GET['width']) ) 
    13     $height = (int) $_GET['width']; 
     13    $width = (int) $_GET['width']; 
    1414 
    1515$margin = 5; 
     
    3939} 
    4040.yarpp-thumbnails-horizontal .yarpp-thumbnail > img, .yarpp-thumbnails-horizontal .yarpp-thumbnail-default { 
    41     margin-bottom: 0px; 
    4241    display: block; 
    4342} 
     
    5655    overflow: hidden; 
    5756} 
    58 .yarpp-thumbnail-default > img.yarpp-thumbnail-default-wide { 
    59     height: <?php echo $height; ?>px; 
    60     max-width: none; 
     57.yarpp-thumbnail-default > img { 
     58    min-height: <?php echo $height; ?>px; 
     59    min-width: <?php echo $width; ?>px; 
    6160} 
    62 .yarpp-thumbnail-default > img.yarpp-thumbnail-default-tall { 
    63     width: <?php echo $width; ?>px; 
    64     max-height: none; 
    65 } 
  • yet-another-related-posts-plugin/trunk/template-thumbnails.php

    r632931 r633818  
    1111$options = array( 'thumbnails_heading', 'thumbnails_default', 'no_results' ); 
    1212extract( $this->parse_args( $args, $options ) ); 
    13  
    14 global $_wp_additional_image_sizes; 
    15  
    16 // @todo: add support for other theme-specified sizes? 
    17 // if ( isset($_wp_additional_image_sizes['yarpp-thumbnail']) ) 
    18 //  $size = 'yarpp-thumbnail'; 
    19 // elseif ( isset($_wp_additional_image_sizes['post-thumbnail']) ) 
    20 //  $size = 'post-thumbnail'; 
    21  
    22 if ( isset($size) ) { 
    23     $width = (int) $_wp_additional_image_sizes[$size]['width']; 
    24     $height = (int) $_wp_additional_image_sizes[$size]['height']; 
     13if ( false !== ($dimensions = $this->thumbnail_size()) ) { 
     14    $width = (int) $dimensions['width']; 
     15    $height = (int) $dimensions['height']; 
     16    $size = 'yarpp-thumbnail'; 
    2517} else { 
    2618    $size = '120x120'; // the ultimate default 
    2719    $width = 120; 
    2820    $height = 120; 
     21    $dimensions = array( $width, $height, false ); 
     22    // @todo true for crop? 
    2923} 
    3024 
     
    4337        $output .= "<a class='yarpp-thumbnail' href='" . get_permalink() . "' title='" . the_title_attribute('echo=0') . "'>" . "\n"; 
    4438 
    45         if ( has_post_thumbnail() ) 
     39        if ( has_post_thumbnail() ) { 
     40            $thumbnail_id = get_post_thumbnail_id( get_the_ID() ); 
     41            $downsized = image_downsize( $thumbnail_id, $size ); 
     42            if ( $dimensions['crop'] && $downsized[1] && $downsized[2] &&  
     43                ( $downsized[1] != $width || $downsized[2] != $height ) ) { 
     44                // we want to trigger recomputation of the thumbnail here 
     45                // (only if downsized width and height are specified, for Photon behavior) 
     46                $fullsizepath = get_attached_file( $thumbnail_id ); 
     47                if ( false !== $fullsizepath && file_exists( $fullsizepath ) ) { 
     48                    require_once(ABSPATH . 'wp-admin/includes/image.php'); 
     49                    $metadata = wp_generate_attachment_metadata( $thumbnail_id, $fullsizepath ); 
     50                    if ( !is_wp_error( $metadata ) ) { 
     51                        wp_update_attachment_metadata( get_post_thumbnail_id( get_the_ID() ), $metadata ); 
     52                    } 
     53                } 
     54            } 
    4655            $output .= get_the_post_thumbnail( null, $size ); 
    47         else 
    48             $output .= '<span class="yarpp-thumbnail-default"><img class="yarpp-thumbnail-default-wide" src="' . esc_url($thumbnails_default) . '"/></span>'; 
     56        } else { 
     57            $output .= '<span class="yarpp-thumbnail-default"><img src="' . esc_url($thumbnails_default) . '"/></span>'; 
    4958            // assume default images (header images) are wider than they are tall 
     59        } 
    5060 
    5161        $output .= '<span class="yarpp-thumbnail-title">' . get_the_title() . '</span>'; 
Note: See TracChangeset for help on using the changeset viewer.