• Hi all

    I’m sure this is simple but I can’t see how to do it.

    I know how to add images to a post – Click in the post, Add Media, choose thumbnail.

    This gives me an thumbnail in the post.

    I think what I want to do is link thumbnails to the post so I can control where the thumbnails appear on the page.

    I have a template like this.

    <div class="content_div">
    		<?php
    
    			$car_args = array(
    				'post_type' => 'post',
    				'category_name' => 'car',
    				'order' => 'asc'
    			);
    
    			$cars = new WP_Query($car_args);
    
    			if($cars->have_posts()):
    				while($cars->have_posts()):
    					$cars->the_post();
    		?>
    
    			<article class="service">
    
    		      <div class="right_col">
    
    		          <h4><?php the_title(); ?></h4>
    
    		          <?php the_content(); ?>
    
    		      </div><!--right_col-->
    
    		      <aside class="side_bar">
    		        <ul>
    
                <!-- I would like to add the thumbnails here -->
    
    		        </ul>
    		      </aside>
    
    		  </article><!-- service-->
    
    			<?php endwhile; endif; ?>
    			<?php wp_reset_postdata(); ?>
    
    		</div><!--content_div-->

    I have posts about car’s with category name ‘car’, I’m using the category name in the WP_Query.

    Some of these posts have images. If there are images with the post I would like to add them as a list in the aside.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Sadly, it is not that simple. For your template to work, the images need to be associated with the post. To associate with the post, they are inserted into the content, where you do not want it. So you need a mechanism to either associate media without inserting it into the content, or a way to remove it once the association is made, without removing the association.

    Another idea would be to develop a couple shortcodes that would generate the needed html for the two columns, within the post content. One shortcode gets the images inserted between it’s tags, the other gets the text. If you want the text to wrap under the images when there’s more text than image, this will be tricky to implement.

    One possible easy workaround if it works for your layout is to make the thumbnails just a bit over 1/2 the width of the text block. Now when you insert the images as right justified, they will stack vertically along the right margin and the text will wrap neatly along the left side and then under the images once the images run out. But you need to be satisfied with rather large thumbs (or rather small medium size images) for this to work.

    Thread Starter ttmt

    (@ttmt)

    bcworkz, thanks for your reply. I really wanted to work this out in wordpress but I was running out of time, I had to do it with jQuery. The images were added as thumbnails in the post then I used jQuery to move the images to where I wanted them.

    I can’t believe something like this would be so difficult in WordPress. I’m still going to try and work this out because I’m sure it will come up again.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Link images to post.’ is closed to new replies.