Forums

How to create a page that presents all post images? (4 posts)

  1. modwest
    Member
    Posted 3 years ago #

    I am trying to figure out if this: http://www.portlandonfire.com/archive/ is custom work, or a plugin, or a setting?

    Thanks in advance for any help!

  2. Michael Fields
    Theme Wrangler
    Posted 3 years ago #

    The answer would be "custom work" using WordPress functionality. This is pretty easy to achieve. Just plug the following code into your themes' archives.php file make sure you overwrite the Loop that you have in there right now:

    <?php
    	/* WordPress Loop - Display only linked thumbnails
    	==================================================== */
    	if (have_posts()) :
    		while (have_posts()) : the_post(); update_post_caches($posts);
    			$images = get_children(
    				array(
    					'post_parent' => $post->ID,
    					'numberposts' => 1,
    					'post_status' => 'inherit',
    					'post_type' => 'attachment',
    					'post_mime_type' => 'image',
    					'order' => 'ASC',
    					'orderby' => 'menu_order'
    				)
    			);
    
    			if ( $images ) {
    				foreach ( $images as $id => $image ) {
    					$img = wp_get_attachment_thumb_url( $image->ID );
    					$link = get_permalink( $post->ID );
    					print "\n\n" . '<a  class="alignleft" href="' . $link . '"><img src="' . $img . '" alt="" />';
    				}
    
    			}
    		endwhile;
    		print '<div class="clear"></div>';
    	else :
    		print '<div class="errorbox">' . __('Sorry, no posts matched your criteria.') . '</div>';
    	endif;
    ?>
  3. Lars M
    Member
    Posted 2 years ago #

    Do you know how I could make this work with the listing of pages instead of posts?

  4. Lars M
    Member
    Posted 2 years ago #

    Solved my problem:

    <?php
    query_posts('post_type=page&post_parent='.$parent);
    ?>
    
    	<?php
    	/* WordPress Loop - Display only linked thumbnails
    	==================================================== */
    	if (have_posts()) :
    		while (have_posts()) : the_post(); update_post_caches($posts);
    
    			$images = get_children(
    				array(
    					'post_parent' => $post->ID,
    					'numberposts' => -1,
    					'post_status' => 'inherit',
    					'post_type' => 'attachment',
    					'post_mime_type' => 'image',
    					'order' => 'ASC',
    					'orderby' => 'menu_order'
    				)
    			);
    
    			if ( $images ) {
    				foreach ( $images as $id => $image ) {
    					$img = wp_get_attachment_thumb_url( $image->ID );
    					$link = get_permalink($page->ID);
    					echo "\n\n" . '<a  class="alignleft" href="' . $link . '"><img src="' . $img . '" alt="" /></a>';
    				}
    
    			}
    		endwhile;
    		echo '<div class="clear"></div>';
    	else :
    		echo '<div class="errorbox">' . __('Sorry, no posts matched your criteria.') . '</div>';
    	endif;
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags