Support » Themes and Templates » Thumbnails in archives page

  • Hi,

    I’m using wordpress for my photoblog, and I’d like to have an archives page with thumbnails of photos shown. Thumbnails are put under excerpt. I’ve modified archives.php and put in the code below:

    <?php while (have_posts()) : the_post(); ?>
    <?php the_excerpt(); ?>
    <?php endwhile; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>
    <?php endif; ?>

    Loading the archives page I get the error

    Parse error: parse error, unexpected T_ELSE in /archives.php on line 15

    with line 15 being <?php endwhile; else: ?>

    What am I doing wrong? How do I get thumbnails to show as archives?

Viewing 12 replies - 1 through 12 (of 12 total)
  • Moderator James Huff


    Return your Archives Template (archives.php) to its original state and replace:

    <?php the_excerpt(); ?>


    <?php the_content(); ?>

    You have no if statement starting off your loop, hence the ‘else’ error. Change the first line to:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    The page loads ok, but thumbnails are not showing

    I skipped over your first post and missed what you were trying to do.

    The reason nothing is showing is that the loop you’re using is (or that is, should be) displaying the excerpt from the Page itself. It knows nothing about the posts archive.

    Doing this through a Page alone can be a bit complicated, but if you set up an archive template as well (archive.php) to display excerpts, you can work them in tandem by changing your Page template’s loop (but leaving the one in archive.php as normal) to something like this:

    <?php $posts = new WP_Query("showposts=10");
    while($posts->have_posts()) : $posts->the_post(); ?>
    <?php the_excerpt(); ?>
    <?php endwhile; ?>

    This sets up a new post query to display in the Page. The WP_Query argument ‘showposts’ defines how many to display in your custom loop, which you can set to as many as you want to be shown on the Page.

    Moderator James Huff


    I skipped over your first post and missed what you were trying to do.

    Me too, sorry.

    Yes, you need to create an Archive.php as a separate page instead of trying to integrate everything into the index.php. I did that on my photoblog.

    Thanks! Thumbnails are showing now 🙂
    But when I click archives for certain month/category I get to the individual posts. How do I get the links to update the archives page with corresponding month/category thumbnails showing?

    Actually, you’re viewing the monthly archive, not individual posts, though it looks like you figured that out since the monthly archive pages look to be showing full months now. As I mention above, place an archive.php in your theme’s directory; easiest way to do this is to copy index.php. Then make the change to The Loop in archive.php to only display an excerpt (i.e. the_excerpt();).


    I just used this thread to make my archives into thumbnail galleries (yay!) but for some reason they are displaying as one long column instead of across the content area (boo!). I don’t have any extra or <br> anywhere, nor any <div> tags so I have no idea why this is happening. Help, please? Aaa!

    I looked in the source file that my archives are generating when I load the page and it look like WP is automatically inserting and <br> tags. Any idea how to stop it from doing this?



    I use css to make the image thumbnails to go across. I have my thumbnails images set to float left, inside a container of a certain width. Hope this helps.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Thumbnails in archives page’ is closed to new replies.