这是一个错误?wp_get_attachment_image返回不同的图像大小
wp_get_attachment_image($attachment_id, 'post-thumb-size-small');
相同的代码,在模板中调用,并在AJAX调用返回相同的图像SRC,但不同的图像宽度和高度。从模板调用
转储:从AJAX
<img width="286" height="189" src="http://localhost/site/files/2012/02/post-image-31-286x189.jpg" class="attachment-post-thumb-size-small" alt="post-image-3" title="post-image-3">
转储调用
<img width="220" height="145" src="http://localhost/site/files/2012/02/post-image-31-286x189.jpg" class="attachment-post-thumb-size-small" alt="post-image-3" title="post-image-3">
我很困惑,什么是错?
的index.php代码
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php include 'post.php'; ?>
<?php endwhile; endif; ?>
post.php中码
<div class="container">
<?php
$theme->theme_post->display_post_element($post_type, $post_size, $post);
?>
</div>
display_post_element功能代码
function display_post_element($post_type, $post_size, $post) {
$attachment_id = get_post_meta($post->ID, '_view_attachment_id', true);
if($post_type == 'single_image') {
$img = wp_get_attachment_image_src($attachment_id, 'full');
if(is_array($img)):
?>
<div class="preview-thumb">
<a href="<?php echo $img[0]; ?>" class="lightbox"><?php echo wp_get_attachment_image($attachment_id, 'post-thumb-size-' . $post_size); ?></a>
<a href="<?php echo $img[0]; ?>" class="lightbox zoom"></a>
</div>
<?php
endif;
}
}
负荷职位与Ajax调用代码:
function load_posts_ajax() {
global $post;
$query_string = $_POST['query_string'];
query_posts($query_string . '&posts_per_page=' . get_option('posts_per_page') . '&post_status=publish&offset=' . (int)$_POST[ 'off']);
if (have_posts()) : while (have_posts()) : the_post();
include TEMPLATEPATH . '/post.php';
endwhile; endif;
die;
}
我在主题构造函数的functions.php中定义了图片大小。 我倾倒了get_intermediate_image_sizes()和所有图像大小加载AJAX调用
这仍然是WP 4.0中的一个问题。我需要正确的尺寸,不能通过图像去显示图像。你有没有找到其他的解决方法?谢谢 – Alvaro 2014-11-05 16:58:57