• Hi.

    I’ve been searching everywhere, and i can’t seem to find the solution.

    My problem is i want to take the image out of <p> in a post, and have the image on the left and the Post title “h2” date and text on the right. Like here: https://psd.tutsplus.com/

    I’m thinking 2 divs are maybe the solution but i dont know how. I want to do this permanently, so that i don’t have to fix it everytime i write a post.

    I hope someone can help me. Thanks in advance.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You can’t set your theme up to do this right from the post editor. The post title is always going to be above the content of the post, and if you add your image to the post, it is in the content, and therefore stuck below the post’s title.

    So what you see on many magazine style themes like PSD TUTS is actually a hack or workaround of sorts. If you take a look at their source code, you can see that each one of those posts is in a div, and at the top is the image, which is then floated to the left, and below that the post starts.

    They are almost certainly archiving this effect with custom fields. Basically, you upload that image separately before you make the post, then you take the URL of that image, paste it into that post as the value of a custom field with the key of “thumbnail” or some such thing.

    Then in your code, you have a mini-loop that is getting the posts and excerpts, and it is also pulling the value of that custom field and adding it as the source of an image above the posts.

    Many commercial themes use this technique. One free theme that you could use as a reference is Smashing Magazine’s Magazeen theme.

    Check out the Featured News section in the sidebar of the demo. Notice that the images are before the post titles? That’s a dead give away that they are using custom fields. Check out the code in functions.php that is making that happen:

    <li id="featured-news"><h5>Featured News</h5>
    		<ul>
    
    			<?php
    				$recent = new WP_Query( 'showposts=' . $number . '&category_name=' . $category );
    				while( $recent->have_posts() ) : $recent->the_post();
    					global $post; global $wp_query;
    			?>
    
    			<li class="clearfix">
    				<?php if( get_post_meta( $post->ID, "image_value", true ) ) : ?>
    
    					<div class="sidebar-preview">
    						<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
    							<strong><img src="<?php bloginfo( 'template_directory' ); ?>/timthumb.php?src=<?php echo get_post_meta( $post->ID, "image_value", true ); ?>&amp;w=109&amp;h=60&amp;zc=1" alt="<?php the_title(); ?>" /></strong>
    						</a>
    					</div>
    
    				<?php endif; ?>
    				<div class="sidebar-content">
    					<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    					<span><a href="<?php the_permalink(); ?>/#comments" title="Read Comments"><?php comments_number('0 Comments', '1 Comment', '% Comments' );?></a></span>
    				</div>
    			</li>
    
    			<?php
    				endwhile;
    			?>
    
    		</ul>
    		<a href="<?php echo get_category_link( get_cat_id( $category ) ); ?>" class="sidebar-read-more">Read More &raquo;</a>
    	</li>

    That’s how they use custom fields to move an image above the post title. This example is a little more complicated than it really has to be, but I suggest downloading this theme and ripping it apart. The theme uses custom fields in a few different places, so between that theme and the WordPress documentation, you should be able to come up with a system that works for you.

    The way the site you provided is doing is with CSS. The CSS says that any img within the ‘content’ id will float to the left and have some spacing around it. Check it out-

    HTML (simplified)

    <div id="content">
      <div class="exerpt preview" id="post-2707">
      <a href="https://picture.com/pictures"><img src="https://picture.com/picture.jpg" alt="" /></a>
      <h1><a href="https://mysite.com/thisPost">The Title</a></h1>
      <small>Mar 18th in <a href="https://mysite.com/category1" title="View all posts in Category1" rel="category tag">Category1</a> by <a href="https://mysite.com/author" title="Posts by Author">Author</a></small>
      <div class="user_comments">
        <span><a href="https://mysite.com/category1/#comments" title="Comments">##</a></span>
      </div>
      <div class="text">
        Blah blah blah <a href="https://mysite.com/category1/more" class="more-link">Continue Reading</a>
    
      </div>
    </div>

    CSS

    #content .exerpt img {
      float: left;
      margin-right: 20px;
      margin-bottom: 20px;
      width: 200px;
      height: 200px;
    }

    This way whenever you put an image in your post, it will be “caught” by the CSS and floated over to the left. Try that out. Have fun.

    [signature moderated Please read the Forum Rules]

    Thread Starter utskiboo

    (@utskiboo)

    OMG I’m such a noob with this php code.

    I’ve been using 3 hours now and i can’t make anything work.
    I’ve been searching for Custom field images but it’s impossible for me to make it work.

    Is there a step by step guide to do this?

    If i erase something from a code, it’s probalbly the wrong part….

    Please help…

    Sorry utskiboo, like I said, this is really more of a hack. Your average free theme doesn’t use these techniques, mostly just commercial themes, so it can be hard to find documentation.

    I suggest you try out a few themes like Magazeen to get a feel for how it works. And if you are struggling with the code, you may have better luck starting with a theme that already includes this functionality.

    Thread Starter utskiboo

    (@utskiboo)

    Okay ??

    But thanks anyway ??

    Hi!

    To get the post image above the post header is quite easy to do within the css (style.css). Without using any plugins or having to upload the picture before. Just use the image uploader in the admin panel!

    Like this:
    – set ‘float: left’ on the image
    – set a positive value on ‘margin-top’ to move the ‘<h2>’ downwards
    – set a negative value on ‘margin-top’ to move the image upwards

    With this solution you have to use a fixed height on your pictures.

    Email me if you have questions!

    God night,
    Nils

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘image before title’ is closed to new replies.