• jezthomp

    (@jezthomp)


    I’m wondering if there is anyway you can control the body image css via the admin and custom fields.

    So post A you could upload an image to the admin and then put its name in the custom field for that post and when you visited that post the background image would be the image you just uploaded…?

    Something like this on the posts page..

    <style type="text/css">
    	body {background-image:url(/<?php bloginfo('template_directory'); ?>/uploads/custom_field_image_path.jpg);background-repeat:repeat;}
    	</style>

    Can this be done?

    Thanks ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • peterwongpp

    (@peterwongpp)

    Is the image only apply to a single post? (as for other case like category page, there is a number of posts that may have different images)

    If in this case (only for a single post), I suggest to add something like the followings into the single.php inside the loop:

    <?php
      $imageName = get_post_meta($post->ID, "CustomFieldNameForTheImage", true);
      if($imageName != '') { ?>
        <style type="text/css">
            body { background-image:url(<?php bloginfo('template_directory'); ?>/uploads/<?php echo $imageName ?>.jpg);background-repeat:repeat;); }
    <?php
      }
    ?>

    The problem is that style tag inside body will cause validating error.

    ThorHammer

    (@thorhammer)

    You can also have several post-templates, styled differently. This option will make you work faster with less custom fields to worry about. And you will pass validation.

    Michael

    (@alchymyth)

    assuming the you have the absolute path to your image in your custom field, and the custom field key is ‘post_background’, and your post is in a div with the class .post, and that you have set the default or other background properties in style.css; you could try something like this:

    <?php $bg_img = get_post_meta($post->ID,'post_background',true); ?>
    <div class="post"<?php if($bg_img != '') { echo ' style="background-image: url(' . $bg_img . '); "' ; }  ?>>
    <!-- your usual code to show the title, posts, postmetadat etc -->
    </div>
    Thread Starter jezthomp

    (@jezthomp)

    Thanks for your input guys.

    Basically its for a portfolio site and each time you go onto a post or page they want the background body image to change to a big photo of their work, with the post content textual etc over the top..

    Thats the gist of it…

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Post Body Background/CSS Controlled Via Admin?’ is closed to new replies.