WordPress.org

Support

Support » Plugins and Hacks » Images in my archive

Images in my archive

  • I have a frustrating question to ask, it’s taking me aaages to find an answer through Google. The concept is deceivingly simply yet the execution seems like a nightmare!! I’m sure someone who has more programming brains than I do figured out a solution…please share your brilliance with a poor soul.

    In my archive,
    I would like a thumbnail of the posts images for each archive post. Does anyone know the php query to call up the image?

    I was thinking it would be something like ;

    the_title();

    ie the_image();

    so for each entry on the archive, it would call up a thumbnail to the list.

    Thanks for having a think for me!

Viewing 5 replies - 1 through 5 (of 5 total)
  • vivekdhar
    Member

    @vivekdhar

    No responses – huh? I’ve been looking for the same thing…

    one alternative solution is you can call the thumbnail ‘manually’ like i did:

    <ul id="archivelist">
    		<?php while (have_posts()) : the_post(); ?>
    
    			<li class="title"><a href="<?php the_permalink();?>">
    			<img src="http://www.example.com/images/thumb-<?php echo $post->post_name;?>.jpg" alt="<?php the_title();?>"/>
    			<span class="archivetitle"><?php the_title();?></span><small><strong>Category:</strong> <?php
    foreach((get_the_category()) as $cat) {
    echo $cat->cat_name . ' ';
    } ?><?php the_time('F j, Y'); ?></small></a></li><?php endwhile; ?>
    			</ul>

    this line: <?php echo $post->post_name;?> will call your slug name. so be sure to name your thumbnail exactly the same with your post slug.

    First, create a function.php file in your theme directory.
    Then paste this into it:

    <?php
    function postimage($size=medium,$num=1) {
    	if ( $images = get_children(array(
    		'post_parent' => get_the_ID(),
    		'post_type' => 'attachment',
    		'numberposts' => $num,
    		'post_mime_type' => 'image',)))
    	{
    		foreach( $images as $image ) {
    			$attachmenturl=wp_get_attachment_url($image->ID);
    			$attachmentimage=wp_get_attachment_image( $image->ID, $size );
    
    			echo '<a href="'.$attachmenturl.'" rel="lightbox">'.$attachmentimage.'</a>';
    		}
    	} else {
    		echo "No Image";
    	}
    }
    ?>

    Then,, wherever in the loop you want a post’s attached image displayed, put

    <?php postimage('thumbnail'); ?>

    If you just insert

    <?php postimage(); ?>

    you’ll get the newest attached image in full size.

    mariostella
    Member

    @mariostella

    Mores, I did as you said but I got

    Fatal error: Call to undefined function: postimage() in /home/mysite/public_html/wordpress/wp-content/themes/default/page.php on line 159

    so i copied your function in the functions.php file of my theme, and it works…however I would like this function to call a specific pic from a specific gallery of nextgen gallery…do you think this is possible? I have zero knowledge of php, so maybe this is a simple matter and a nobrainer to you…

    pfft, I dunno. I have no idea how nextgen gallery works.
    What my code does is simply check for all uploads that are attached to the current post.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Images in my archive’ is closed to new replies.