• I hope I’m posting in the right section.

    In a theme I’m locally developing, I want to display the post title under the first image of the post.

    I used the function <?php getImage('1') ?> to put it in a div before the title. Then I call the content while removing the pictures from it
    thanks to this piece of code:

    <?php ob_start();
    the_content('Read the full post',true);
    $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
    ob_end_clean();
    echo $postOutput; ?>

    The only thing I need now is getting all the pictures attached to the post to show up in there own div. Here is the code I use:

    <?php $args = array(
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'orderby' => 'menu_order',
    'post_parent' => $post->ID);
    $images = get_posts( $args );
    foreach($images as $image):
    echo wp_get_attachment_image($image->ID, 'large');
    endforeach; ?>

    My problem is that my first picture appears twice in the post.
    Once before the title (in the first div) and then in the last (with the rest of the pictures).
    How can I make the first image disappear from my last div (i.e get all the attachment images BUT the first one)?

    I’ll be glad if some php guru can help me!
    thanks

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Display only the last attachment images (hide the first)’ is closed to new replies.