[Plugin: Top 10] Filter for image link
-
Hi,
I started using the plugin, but wasn’t happy with the fact that the post images were not the right size, so I added a filter in the plugin to get a place to customize the url.This is the code, if you find it useful you can add it to the next version of the plugin!
function tptn_get_the_post_thumbnail($postid) { $result = get_post($postid); $tptn_settings = tptn_read_options(); $output = ''; if (function_exists('has_post_thumbnail') && has_post_thumbnail($result->ID)) { $postimage = wp_get_attachment_image_src( get_post_thumbnail_id($result->ID), 'thumbnail'); $postimage = apply_filters( 'tp10_postimage', $postimage[0], $tptn_settings[thumb_width], $tptn_settings[thumb_height] ); $output .= '<img src="'.$postimage.'" alt="'.$title.'" title="'.$title.'" style="max-width:'.$tptn_settings[thumb_width].'px;max-height:'.$tptn_settings[thumb_height].'px;" border="0" class="tptn_thumb" />'; // $output .= get_the_post_thumbnail($result->ID, array($tptn_settings[thumb_width],$tptn_settings[thumb_height]), array('title' => $title,'alt' => $title, 'class' => 'tptn_thumb', 'border' => '0')); } else { $postimage = get_post_meta($result->ID, $tptn_settings[thumb_meta], true); // Check if (!$postimage && $tptn_settings['scan_images']) { preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i', $result->post_content, $matches ); // any image there? if (isset($matches) && $matches[1][0]) { $postimage = $matches[1][0]; // we need the first one only! } } if (!$postimage) $postimage = get_post_meta($result->ID, '_video_thumbnail', true); // If no other thumbnail set, try to get the custom video thumbnail set by the Video Thumbnails plugin if ($tptn_settings['thumb_default_show'] && !$postimage) $postimage = $tptn_settings[thumb_default]; // If no thumb found and settings permit, use default thumb if ($postimage) { $postimage = apply_filters( 'tp10_postimage', $postimage, $tptn_settings[thumb_width], $tptn_settings[thumb_height] ); $output .= '<img src="'.$postimage.'" alt="'.$title.'" title="'.$title.'" style="max-width:'.$tptn_settings[thumb_width].'px;max-height:'.$tptn_settings[thumb_height].'px;" border="0" class="tptn_thumb" />'; } } return $output; }It can be slightly optimized, but I didn’t do it to keep the modifications to the code minimal.
Hope it helps.
Riccardo
http://www.gurtip.it
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
The topic ‘[Plugin: Top 10] Filter for image link’ is closed to new replies.