Images in my archive (6 posts)

  1. adger560
    Posted 8 years ago #

    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 ;


    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!

  2. vivekdhar
    Posted 8 years ago #

    No responses - huh? I've been looking for the same thing...

  3. soyuz
    Posted 8 years ago #

    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; ?>

    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.

  4. mores
    Posted 8 years ago #

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

    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 ) {
    			$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.

  5. mariostella
    Posted 8 years ago #

    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...

  6. mores
    Posted 7 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic