Support » Fixing WordPress » Featured Image archive with fallback image selection.

  • Hi,

    I want to have a yearly archive of all posts within a certain category, using the featured image as a permalink to the post.

    Actually, I have this working but since I have only recently started using featured images, most of the posts don’t have an image yet.

    My idea is to have set images for each category to fallback on if the featured image isn’t found.

    Here is what is working:

    <?php query_posts('cat=81&year=2011'); ?>
    	<?php while (have_posts()) : the_post(); ?>
    		<?php if ( has_post_thumbnail()) :>
    			<a href="<?php the_permalink(); ?>"><?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );?><img src="<?php echo $url; ?>" title="<?php the_title_attribute(); ?> <?php the_time('jS F Y') ?>" height="90" width="180" /></a>
    		<?php endif; ?>
    	<?php endwhile; ?>

    Now, when I try and add Else If statement it all falls apart. I am sure I am making an elementary PHP error but can’t see it.

    Here is what I currently have:

    <?php query_posts('cat=81&year=2011'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if ( has_post_thumbnail());
    <a href="<?php the_permalink(); ?>"<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );?><img src="<?php echo $url; ?>" title="<?php the_title_attribute(); ?> <?php the_time('jS F Y') ?>" height="90" width="180" /></a>;
    else if(in_category(91)) : ?>
    <a href="<?php the_permalink(); ?>"><img src="/media/admin/hl1-thumbnail.jpg" title="<?php the_title_attribute(); ?> <?php the_time('jS F Y') ?>"></a>;
    <?php else if(in_category(406)) : ?>
    <a href="<?php the_permalink(); ?>"><img src="/media/admin/hl2-thumbnail.jpg" title="<?php the_title_attribute(); ?> <?php the_time('jS F Y') ?>"></a>;
    <?php endif; ?>
    <?php endwhile; ?>

    I need another 6 Else If statement but removed them for clarity. I’ve tried a bunch of variations but nothing sdeems to work.

    Any help will be greatly appreciated.

    I will be putting them into a template and creating a new page for each year.

    TIA

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Featured Image archive with fallback image selection.’ is closed to new replies.