Custom Category Archive
-
Hi there!
I am trying to create a category archive for my blog which is image based! I can’t provide a link as I am developing it locally! I have it working how I want, kind of, but need help making it a lot better!
I want to display the latest post (which is an image) for each category on the one page and for it to act as a link to all the posts in that specific category. See code below for what I have so far…
<div class="mainmargin" id="grid-content"> <div class="topline"></div> <div <?php post_class("post_float2") ?>> <?php $category_id = get_cat_ID( 'Branding' ); $category_link = get_category_link( $category_id ); ?> <?php query_posts('category_name=branding&showposts=1'); ?> <?php while (have_posts()) : the_post(); ?> <?php $img = getAttachedImage($post->ID, "medium"); if ($img and $img != get_bloginfo("template_directory") . '/images/no_image.jpg') : $img_size = getimagesize($img); ?> <a class="img_link" title="<?php the_title(); ?>" href="<?php echo $category_link; ?>" title="Branding"><img class="fade attached" src="<?php echo $img; ?>" alt="<?php the_title(); ?>" <?php echo $img_size[3]; ?> /></a> <?php endif; ?> <?php endwhile; ?> </div> </div>This displays the latest image in Branding Category and links to all the Branding images but the only way I can get it to work for more categories is to just duplicate the same php code and link that is within the divs, just changing the category name each time.
I’m sure this isn’t the best way to do it so I am asking for help to make this code more efficient. Is there a way that I don’t have to duplicate the same code again and again for each category!?
Thank you for anyone’s help and/or solutions
The topic ‘Custom Category Archive’ is closed to new replies.