Hi there,
I have created an image based wordpress blog locally and want to create a category archive page displaying the latest image for each category. Each Image would then link to all the images in that Category.
My code is shown below:
<?php
$catQuery = $wpdb->get_results("SELECT * FROM $wpdb->terms AS wterms INNER JOIN $wpdb->term_taxonomy AS wtaxonomy ON ( wterms.term_id = wtaxonomy.term_id ) WHERE wtaxonomy.taxonomy = 'category' AND wtaxonomy.parent = 0 AND wtaxonomy.count > 0");
$catCounter = 0;
foreach ($catQuery as $category) {
$catCounter++;
$catStyle = '';
if (is_int($catCounter / 2)) $catStyle = ' class="catAlt"';
$catLink = get_category_link($category->term_id);
echo '<li'.$catStyle.'><h3><a href="'.$catLink.'" title="'.$category->name.'">'.$category->name.'</a></h3>';
echo '<ul>';
query_posts('cat='.$category->term_id.'&showposts=1');?>
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class("post_float2") ?>>
<?php
$img = getCatImage($post->ID, "medium");
?>
<li><a href="<?php echo $catLink ?>" rel="bookmark" title="<?php the_title(); ?>"><img class="fade attached" src="<?php echo $img; ?>" alt="<?php the_title(); ?>" /></a></li>
</div>
<?php endwhile; ?>
</ul>
</li>
<?php } ?>
I am also using a function as shown here:
<?php
function getCatImage($category_ID, $size) {
//$size = 'medium';
if ($images = get_children(array(
'post_type' => 'attachment',
'numberposts' => 1,
'post_status' => null,
'post_parent' => $post_ID,))) {
foreach($images as $image) {
$attachment = wp_get_attachment_image_src($image->ID, $size);
}
$related_img_src = $attachment[0];
//$related_img_src = ($attachment[0]) ? $attachment[0] : get_bloginfo("template_directory") . '/images/no_image.jpg';
} else {
$related_img_src = get_bloginfo("template_directory") . '/images/no_image.jpg';
}
return $related_img_src;
}
?>
I have everything linking ok but the image shown for each category is the same image repeated. So I have 6 categories and exactly the same image displaying for each category! I want to know how to change the loop/function to display the latest image for each category.
I am completely lost now! Have tried for a couple of days but my knowledge is spent!
Please, please help someone!?
Thank you