latest post as background image? (5 posts)

  1. karlotta
    Posted 5 years ago #


    I have a photography website (http://www.karlotta.com) 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!

  2. karlotta
    Posted 5 years ago #

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

  3. alchymyth
    Forum Moderator
    Posted 5 years ago #

    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.

  4. karlotta
    Posted 5 years ago #

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

  5. karlotta
    Posted 5 years ago #

    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> http://www.karlotta.com/wordpress/wp-content/gallery/babies/babies004.jpg</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.

Topic Closed

This topic has been closed to new replies.

About this Topic