2012-10-15 33 views
0

我正在处理108.179.217.161这是一个自定义WordPress主题,我在主页上有一个滑块设置。但是,在每个单独的页面上,我想使用精选图像作为实际的主图像,并在主页上使用旋转器。WordPress主题不能正确显示图像

我正在使用一个小部件的旋转器和if语句来区分页面是否不是主页,但图像不能正确呈现。见108.179.217.161/contact-us/。

下面是我的代码:

<div id="slider" style="position:relative;height:679px;width:100%;"> 
<!--<img width=1228 src="<?php bloginfo(template_url)?>/images/room-slider.png" alt="" style="position:absolute;z-index:-20;width:100%;height:679px;"/>--> 
<div style="position:absolute;z-index:-20;width:100%;height:679px;overflow:hidden;"> 
<?php if (is_page('Home')) {?> 
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Rotator')) : ?> 
[ do default stuff if no widgets ] 
<?php endif; ?> 
<? } else { 
    $thumb = get_post_meta($post->ID,'_thumbnail_id',false); 
    $thumb = wp_get_attachment_image_src($thumb[0], 'header', false); 
    $thumb = $thumb[0]; 
echo "<img src='$thumb' alt='' style='position:relative;z-index:1;width:1621px;height:679px;'"; 
}?> 
</div> 

回答

0

棘手的业务WordPress的那些附件!

首先,您在wp_get_attachment_image_src调用中调用'header'图像大小。你有没有在functions.php文件中定义这个自定义图像大小?

接下来,请确保您的媒体页面上的文件实际上已附加到您的帖子或页面。我假设你的代码在循环中?否则,你需要告诉wordpress你正在使用的页面/帖子。请参阅wp_query。

接下来,您是否可以确认if()语句检测到非主页,您可以回显“无主页”或类似内容,以便知道该函数本身的作用?

最后,我得查了这一点,但我认为,当你拨打:

$thumb = get_post_meta($post->ID,'_thumbnail_id',false); 

然后指的是返回的值,在未来路线为:

$thumb[0] 

我不确定你从get_post_meta得到了一个关联数组。根据食典,他们说“这个函数返回自定义字段的值”。

但是关于wp_get_attachment调用,Codex说:“返回一个包含图像属性的数组”。所以你在这里引用一个返回数组是正确的。

所以我建议的重新编写,这将是:

$myID = get_post_meta($post->ID,'_thumbnail_id',false); 
$myPic = wp_get_attachment_image_src($myID, 'header', false); 
$thumb = $myPic[0]; 

希望帮助 - 我会稍后再检查,看看是否你有任何进展

里克