這是一個錯誤?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