• Resolved Sinopa

    (@sinopa)


    Does anyone know how I can get the all images in a post to display above the post title? Been searching, but found no good solutions 🙁

Viewing 8 replies - 1 through 8 (of 8 total)
  • You would need to modify the content or loop file, it would also depend on the theme you are using.

    It is not a normal request, are you using the [gallery] shortcode to group the images?

    HTH

    David

    Thread Starter Sinopa

    (@sinopa)

    No I’m not using the [gallery] shortcode and I knew I would have to modify the loop/content. But I don’t know how.

    I’m working on a template for a customer and they just want to upload images to a post and add some text and a post title, but they want the title below the images. I have seen it done before, but I just don’t know how to do it.

    Are the images inside the post content or attached to the post?

    If they are in the post content then just move the post title below the content and before the comments, in the single page loop.

    If you mean find all attachments and output these then that is a different process, have a look at the codex example and output the images instead of links.

    Both of these would be in single.php

    David

    Thread Starter Sinopa

    (@sinopa)

    They are inside the post.
    If I move the title below content, then the post text will also be above the title. I just want the images above the title. Not the text. So that will not work.

    Thread Starter Sinopa

    (@sinopa)

    I’m actually closer to a solution with a little help from Google. The only problem now is that it only shows the first picture. If the post have several pictures it doesn’t show them all.

    functions.php

    function catch_that_image() {
      global $post, $posts;
      $first_img = '';
      ob_start();
      ob_end_clean();
      $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_img = $matches [1] [0];
    
      if(empty($first_img)){ //Defines a default image
        $first_img = "/images/default.jpg";
      }
      return $first_img;
    }

    index.php

    <img src="<?php echo catch_that_image() ?>" />
     <?php the_title(); ?>
                 <?php the_excerpt(); ?>

    The code example above would work for this, I will have a look this evening (UK) and see if I can create a quick function for you, it might be of use for someone else!

    As you are using excerpt and index.php can you post all of index.php up to http://pastebin.com

    HTH

    David

    Based on the codex plus a bit extra, three thumbnail images across, change for what you want!

    This goes in functions.php
    http://pastebin.com/2scCLiTy

    This goes in style.css
    http://pastebin.com/d4WKfVPW

    To call the function in the “content.php” “loop.php” above the post class

    <?php dr_Get_Post_Images(); ?>

    This is it after rebulding the thumbnails in twenty eleven to generate the new image size.
    http://digitalraindrops.net/images/post-thumbs.png

    HTH

    David

    Thread Starter Sinopa

    (@sinopa)

    Thank you so very much Digital Raindrops 🙂

    Sorry that I haven’t answered you, but been a way for a couple of days and wordpress was the last thing on my mind yesterday 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Images in post above post title’ is closed to new replies.