【发布时间】:2017-09-24 22:14:44
【问题描述】:
感谢您查看此处并尝试提供一些有用的答案。最近我下载了插件https://wordpress.org/plugins/olevmedia-shortcodes/,效果很好。但是,当尝试使用“Recent Post”的短代码时,我遇到了与图像尺寸相关的问题,您可以在下面的图片中看到:
它看起来真的很丑。我打开了一段代码,找到了这个函数的一小段代码:
$out .= '<div class="omsc-recent-posts-title"><h3><a href="'. get_permalink() .'">'. get_the_title() .'</a></h3></div>';
if( $thumbnail && has_post_thumbnail() ) {
$img = wp_get_attachment_image_src( get_post_thumbnail_id(), apply_filters('omsc_sc_recent_posts_img_size', 'medium'));
if($img) {
$img_html=apply_filters('omsc_sc_recent_posts_img', '<a href="'. get_permalink() .'"><img src="'.$img[0].'" alt="'.esc_attr($post->post_title).'" /></a>', array(
'img_src' => $img[0],
'link' => get_permalink(),
'alt' => $post->post_title,
));
$out.='<div class="omsc-recent-posts-thumb">'.$img_html.'</a></div>';
}
}
然后我查看图像大小,它说:
$img = wp_get_attachment_image_src( get_post_thumbnail_id(), apply_filters('omsc_sc_recent_posts_img_size', 'medium'));
通过 FireBug 检查某些帖子的“中”尺寸设置为 222x221,其他帖子设置为 300x300,其余为 222x167
我要做的就是使所有缩略图具有相同的大小。所以,我为我的主题的 function.php 文件创建了这段代码:
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'custom-recpost-thumb', 222, 221,true );
}
然后对于插件 php 文件,我以这种方式调用了该函数:
$img = wp_get_attachment_image_src( get_post_thumbnail_id(), apply_filters('omsc_sc_recent_posts_img_size', 'custom-recpost-thumb'));
我也看到了。绝对没有进行任何更改。我做错了什么?
【问题讨论】: