Support » Themes and Templates » latest post as background image?

  • Hi!

    I have a photography website ( powered entirely by WP and NextGen Gallery.

    On the index page, I’d like to post a new photo every few days, with the date and a title. (there’s a dummy photo + text in there now if you want to see the desired end result!)

    So this sounds pretty simple, except that because of the structure of my site, the image in question is actually the background of a div, not an img tag inside the post. It cannot be anything else than that for formatting reasons.

    So I was wondering if there was a script I could use to define that background image – as a variable in my css, maybe?

    My CSS is an external sheet, but I would be open to having that one element defined in the head (or body?) if that helps. I just can’t think of a good way to accomplish what I want.

    Anybody’s got a thought on this little mystery?

    Many thanks for your help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • I had actually found a super great way : defining the background of the div in the body, as the <post_content> tag – and then I’d post the URL of the image.

    Except that brilliant WordPress engineers thought it would be better to hardwire a <p> in the code …



    Forum Moderator

    if you use <?php echo get_the_content(); ?> then there won’t be <p> tags.
    however, an image in a post would likely be surrounded by some html tags. which in turn could be stripped using php string operations.
    custom fields might be another possibility.

    Sorry my server was down last night and I couldn’t test – thank you for this solution, but unfortunately, it didn’t work : the <p> is still there!

    It makes me SO MAD that WP thinks they can decide to put a <p> in my page without asking. It’s screwing things up for a lot of people.

    I’m going to end up doing the custom fields, but it’s unnerving to have to find a workaround because SOMEBODY THOUGHT IT WAS A GREAT IDEA TO HARDWIRE A <P> IN THERE! GOSH! HOW SILLY!!!!

    After the <p> fiasco I tried to use the option of custom fields, but of course, <?php the_meta(); ?> doesn’t just give you the value (which would be the URL to my background photo), it wraps it in a ton of useless code –

    <div id="content" align="center" style="background-image:url(<ul class='post-meta'>
    <li><span class='post-meta-key'>index photo:</span></li>

    What good is that to me? What can I do now? All I want is to type something in a field somewhere and have it come out THE SAME WAY iN MY CODE!

    I’m getting so frustrated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘latest post as background image?’ is closed to new replies.