• Hi!
    I’m having a problem in a website that I’m building.
    Currently I’m using the Feature Image as a post background.

    <?php global $post; ?>
    <?php $args = array( 'numberposts' => 20 ); $lastposts = get_posts( $args ); foreach($lastposts as $post) : setup_postdata($post); ?>
    <div class="adsContainer" style="background-image: url('<?php $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' =>'image') ); foreach ( $attachments as $attachment_id => $attachment ) { echo wp_get_attachment_url( $attachment_id, 'medium' ); } ?>')">
    <div id="textHolder"><?php the_content(); ?></div><!-- end of textHolder --></div>
    <?php endforeach; ?>

    But I also need to be able to show an image inserted into the post.

    Does it make sense? I need a background for each post (it’s working fine) but I also need to be able to display a image inserted in the post.

    Thanks

Viewing 11 replies - 1 through 11 (of 11 total)
  • You should still be able to embed an image in the post, does it not show up when you do?
    Normally the featured image would appear with whatever embedded image. not sure why that would change.

    Thread Starter iconio

    (@iconio)

    Yeah.. what’s happening is that every time I insert a Featured Image and a Image because the featured one is the background it doesn’t show anything.
    It writes both of them in one line like

    https://domain.com/images/image.jpghttps://domain.com/images/featimage.jpg

    I don’t know that you can have 2 instances of the_post_thumbnail, which is the php code for the featured image. But, you should be able to embed an image in the post like ussual, and have a featured image for the post as well. Not another instance of the featred image, but a seperate embedded image in the post

    <a href="https://www.linktoslargerversion.jpg"><img src="yourimagesource.jpg"></a>

    Thread Starter iconio

    (@iconio)

    But how am I gonna do that?

    Thread Starter iconio

    (@iconio)

    I don’t think I made myself clear.

    The way I have things set right now is, every single post from all categories it’s been display on the HOME page. But each one of them has its own background, this background it’s the featured image.

    Whenever I try to insert an image, the background for that specific post disappears but the inserted image shows fine. When I look at the code the background image (featured) has its own path (ok) but also has the inserted image path, that’s the reason it doesn’t show de background anymore.

    ooooh, sorry I thought you wanted to see the featured image in the post like they are normally used, as well as a background. Your issue is pretty unique, sounds like a bug in the way wp uses the featured image as a background. I wouldn’t know how to fix that.
    This is all new to me as I’ve never encountered background featured images for posts. Closest I’ve seen is twentyeleven theme featured image header.

    There should be some workarounds you could try, prehaps an in-page widget for images? Maybe some way to use custom fields? Maybe a plugin which uses shortcode to get images? or even one which handles images differently, outside the wp media library (like next gen gallery) If I think of anything else I’ll share. Good luck.

    Thread Starter iconio

    (@iconio)

    That’s what I was afraid to hear! lol ??

    I’ll try to use the next gen gallery to see what happens…

    Thank you very very much!

    If I got any success I’ll share!

    Thank you

    I tried this one and it worked, although I don’t have a featured image, background or otherwise. Still the code works, may be a solution for you…?

    Okay, I tried it with a featured image, like ussual (not as background) and it still gets the image assigned to the custom field as well as the featured image. looks promising ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Feature Image and inserted image’ is closed to new replies.