Support » How-To and Troubleshooting » attachment_url not

attachment_url not

  • Hi,

    I’d like to use each first gallery image of a child page to be displayed as a div background on the parent page. This works for some pages, but others aren’t displaying an image;

    $attachments = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order'));
    if ( ! is_array($attachments) ) continue;
    $count = count($attachments);
    $first_attachment = array_shift($attachments); ?>
    <a href="<?php the_permalink(); ?> ">
    						<li class="profile_pic" style="background: url('<?php echo wp_get_attachment_url($first_attachment->ID); ?>') center no-repeat; background-size: cover;">

    The child pages I created earlier show the proper bg image, while new pages leave it blank (same template, same parent). I figured it can’t be CSS, nor the PHP code, since some of them work just fine.

    Here goes nothing, help me out!

  • The topic ‘attachment_url not’ is closed to new replies.