Ask your WordPress questions! Pay money and get answers fast! (more info)

browse thumbs by post_date WordPress

I have many many images/posts in 6 categories.
I'd like to do a gallery where I group and show thumbs by post_date, filtered by a category or maybe author.

So say I had an ART gallery-page, I'd see the latest series only (maybe 3 pix) and then click backwards in time to the next that might have 1 thumb. I would range the amount of pics/posts from 1 to 6, so optimally as an add-on I would like to style my thumb size accordingly.

I have one picture per post

if you could make the posts from
wp_get_archives('type=daily&show_post_count=1')
browseable then we'd be close

any ideas?



Answers (3)

2012-12-19

Arnav Joy answers:

please see these two examples

http://www.rlmseo.com/blog/get-images-attached-to-post/

http://www.wpoutfitters.com/2011/01/wordpress-image-attachment-gallery-revisited/


http://wordpress.org/extend/plugins/my-post-image-gallery/


Arnav Joy comments:

define this to functinos.php

<?php

function wpse_get_images($post_id) {
global $post;
$id = intval( $post_id );
$size = 'medium';
$attachments = get_children( array(
'post_parent' => $id,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order'
) );
if ( empty( $attachments ) )
return '';

$output = "\n";
/**
* Loop through each attachment
*/
foreach ( $attachments as $id => $attachment ) :

$title = esc_html( $attachment->post_title, 1 );
$img = wp_get_attachment_image_src( $id, $size );

$output .= '<a class="selector thumb" href="' . esc_url( wp_get_attachment_url( $id ) ) . '" title="' . esc_attr( $title ) . '">';
$output .= '<img class="aligncenter" src="' . esc_url( $img[0] ) . '" alt="' . esc_attr( $title ) . '" title="' . esc_attr( $title ) . '" />';
$output .= '</a>';

endforeach;

return $output;
}

?>


and use following code in your file

<?php query_posts('posts_per_page=-1&orderby=ID&order=DESC');?>
<?php if ( have_posts() ) : ?>

<?php while ( have_posts() ) : the_post(); ?>
<?php echo 'images from post==>'.get_the_title();?>
<?php echo wpse_get_images(get_the_ID();?>
<br /> <br />

<?php endwhile; ?>
<?php endif; ?>





you can use order=ASC or order=DESC in query_posts() , read more about query_posts

http://codex.wordpress.org/Function_Reference/query_posts


Jacob Tekiela comments:

thanks!
but I only have one image per post


Arnav Joy comments:

what you want to say , you have only one image or my code showing only one image to output , if my code has problem then you can use it

function wpse_get_images($post_id) {

global $post;

$id = intval( $post_id );

$size = 'medium';

$attachments = get_children( array(

'post_parent' => $id,

'post_status' => 'inherit',

'post_type' => 'attachment',

'post_mime_type' => 'image',

'posts_per_page' => -1,

'order' => 'ASC',

'orderby' => 'menu_order'

) );

if ( empty( $attachments ) )

return '';



$output = "\n";

/**

* Loop through each attachment

*/

foreach ( $attachments as $id => $attachment ) :



$title = esc_html( $attachment->post_title, 1 );

$img = wp_get_attachment_image_src( $id, $size );



$output .= '<a class="selector thumb" href="' . esc_url( wp_get_attachment_url( $id ) ) . '" title="' . esc_attr( $title ) . '">';

$output .= '<img class="aligncenter" src="' . esc_url( $img[0] ) . '" alt="' . esc_attr( $title ) . '" title="' . esc_attr( $title ) . '" />';

$output .= '</a>';



endforeach;



return $output;

}



?>


if you have only one image to post even in that case my code will work , let me know if there is any problem.


Jacob Tekiela comments:

thanks
I looked into you links and tried your code
but I cant make it work - get a blank screen - have tried to comment out some of the lines
don't know where the error is

the problem is not getting the thumbs but getting them sorted by the date


Arnav Joy comments:

please find this line in my code

<?php echo wpse_get_images(get_the_ID();?>

it is missing a ")" , so replace it with following

<?php echo wpse_get_images(get_the_ID());?>

2012-12-19

phppoet answers:

use this type of filters on ART gallery-page

<?php
$default_attr = array(
'src' => $src,
'class' => "attachment-$size",
'alt' => trim(strip_tags( $wp_postmeta->_wp_attachment_image_alt )),
'title' => trim(strip_tags( $attachment->post_title )),
);?>

2012-12-19

Ellah Alzona answers:

Try this might help:
Copy this code 6 times in a template and change the value of "cat" by your category id to show 6 different categories with 3 latest posts/pics. The rest you need to do some minor style customization.


<?php $blog_query = 'showposts=3&cat=1&paged='.$paged;
$posts = query_posts($blog_query);
while (have_posts()) : the_post(); ?>
<h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?>
<?php endwhile; ?>


The class of your featured image thumbnail will be .attachment-custom_thumb so if you want to style it you can just add these lines to your style.css file (your theme style-sheet) or you are free to modify accordingly to your needs:


.attachment-custom_thumb { float: left; margin: 2px; }


Jacob Tekiela comments:

thanks but the trick is I don't know how many "showposts" to show per series
I might have 6 post in one series and only 1 in another..... depending on the number uploaded that day....

if I could check how many post were genereated on the same date that would be the number
and then you could offset to retrieve next series....?