Forums

[resolved] Custom field in post is showing up on the blog page (3 posts)

  1. geezerd
    Member
    Posted 1 year ago #

    I'm using this to show a div that stretches the whole window, showing a fully stretched image:

    <?php $bg = get_post_meta($post->ID, bg, true);
    if($bg){ ?>
    <div id="page-background"><img src="<?php bloginfo( 'template_directory' ); ?>/images/<?php echo get_post_meta($post->ID, bg, true); ?>" alt="" width="100%" height="100%" /></div>
    <?php }else{ ?>
    <?php } ?>

    Works great, but it if the first (and only first) post on the blog page has that custom field, the whole blog page gets the custom field.
    Anyone know how to remedy this?
    Thanks.

  2. geezerd
    Member
    Posted 1 year ago #

    Just so it's clear:
    The 'if' statement has the custom field meta data with the containing div holding the image, and the 'else' statement is empty. If the top most post on the blog page has the custom field set in it, it shows the image on the blog page. If any other post other than the top most has the custom field, it's fine, it doesn't add the image the the blog page.

  3. geezerd
    Member
    Posted 1 year ago #

    Wasn't in the loop. And can't be, so won't work. Needs to be in a custom header.php file for just pages and single posts.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.