WordPress主题没有正确显示图像

时间:2012-10-15 21:45:15

标签: php html css wordpress wordpress-theming

我正在使用108.179.217.161这是一个自定义的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>

1 个答案:

答案 0 :(得分:0)

棘手的业务那些wordpress附件!

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

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

接下来,您能否确认if()语句是否检测到非主页,您可以回显“NON HOME PAGE”或类似内容,因此您知道该功能本身有效吗?

最后,我将不得不检查这一点,但我想当你致电:

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

然后在下一行中将该返回值称为:

$thumb[0]

我不确定你是否从get_post_meta获得了一个关联数组。根据Codex,他们说“此函数返回自定义字段的值”。

但是关于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];

希望有所帮助 - 我稍后会回来查看你是否有任何进展

瑞克

相关问题