• Hi, thanks for reading this.

    I’ve been using this handy script from digital mash to keep horizontally gridded posts nicely lined up for a while now. It basically inserts a clearing break every 5 posts, or how ever many you choose.

    However, in a current project, I’m using the attachment toolbox described here to display images and descriptions in a horizontal grid with five columns.

    Problem is I can’t combine the two, because the attachment system uses a foreach loop instead of the standard $post loop.

    Here’s my code so far:

    <?php
    function attachment_toolbox($size = thumbnail) {
    
    	if($images = get_children(array(
    		'post_parent'    => get_the_ID(),
    		'post_type'      => 'attachment',
    		'numberposts'    => -1, // show all
    		'post_status'    => null,
    		'post_mime_type' => 'image',
    	))) {
    
    		echo '<br class="clearboth" /><h3>Other Editions:<h3><ul class="otherEds">';
    
    		foreach($images as $image) {
    			$attimg   = wp_get_attachment_image($image->ID,$size);
    			$atturl   = wp_get_attachment_url($image->ID);
    			$attlink  = get_attachment_link($image->ID);
    			$postlink = get_permalink($image->post_parent);
    			$atttitle = apply_filters('the_title',$image->post_title);
    			$attcontent = ($image->post_content);
    
    			echo '<li class="onecolfive left fivecolmargin"><div class="bookimage">'.$attimg.'</div>';
    			echo '<p>'.$atttitle.'</p>';
    			echo '<p>'.$attcontent.'</p></li>';
    
    		}
    
    		echo '</ul>';
    	}
    }
    ?>

    If any body knows how I could modify this to insert a clearing break every 5 attachments, I’d be really pleased to learn.

    Thanks!

    J

Viewing 1 replies (of 1 total)
  • Thread Starter Joshuwar

    (@joshuwar)

    Er, figured it out- it’s not different at all. Here’s what worked for me, in case it’s handy for anyone:

    <?php
    function attachment_toolbox($size = thumbnail) {
    
    	if($images = get_children(array(
    		'post_parent'    => get_the_ID(),
    		'post_type'      => 'attachment',
    		'numberposts'    => -1, // show all
    		'post_status'    => null,
    		'post_mime_type' => 'image',
    	))) {
    
    		echo '<br class="clearboth" /><h3>Other Editions:<h3><ul class="otherEds">';
    		$postcounter = 0;
    
    		foreach($images as $image) {
    			$attimg   = wp_get_attachment_image($image->ID,$size);
    			$atturl   = wp_get_attachment_url($image->ID);
    			$attlink  = get_attachment_link($image->ID);
    			$postlink = get_permalink($image->post_parent);
    			$atttitle = apply_filters('the_title',$image->post_title);
    			$attcontent = ($image->post_content);
    
    			echo '<li class="onecolfive left fivecolmargin"><div class="bookimage">'.$attimg.'</div>';
    			echo '<p><strong>'.$atttitle.'</strong></p>';
    			echo '<p>'.$attcontent.'</p></li>';
    			$postcounter++;
    			if ($postcounter % 5 == 0) {;
    				echo '<br class="clearboth" />';
    				};
    		}
    
    		echo '</ul>';
    	}
    }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘counting attachments and inserting breaks…’ is closed to new replies.