简体   繁体   中英

WordPress Theme Not Showing Images Correctly

I'm working on 108.179.217.161 which is a custom WordPress theme and I have a slider set-up on the Home Page. However, on each individual page, I want to use the Featured Image to be the actual main image and just use the rotators on the homepage.

I am using a Widget Area with a widget for the rotator and and if statement to diferentiate if the page is not the homepage, however the images are not rendering correctly. See 108.179.217.161/contact-us/.

Below is my code:

<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>

Tricky business those wordpress attachments!

First of all, you're calling the 'header' image size inside the wp_get_attachment_image_src call. have you defined this custom image size in the functions.php file?

Next, make sure on your media page, that the files are in fact attached to your post or page. Im presuming that your code above is in a loop? Otherwise you need to tell wordpress what page /post you're on. See wp_query.

Next, Can you confirm that if the if() statement detects a non-homepage, you can echo out "NON HOME PAGE" or similar, so you know the function itself works?

Lastly, and i'll have to check up on this, but I think when you call:

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

And then refer to that returned value in the next line as:

$thumb[0]

Im not sure that you get an associative array back from get_post_meta. According to the Codex, they say "This function returns the values of the custom fields".

But regarding the wp_get_attachment call, the Codex says: "Returns an array with the image attributes". So you are right in referencing a returned array here.

So my suggested re-write for that would be:

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

Hope that helps - I'll check back later on to see if you've had any progress

Rick

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM