Display WordPress Posts as gallery with title

for a project I am working on I have been trying to set up a wordpress post loop on a subpage which woould display all posts as a thumbnail image with the posts title underneath. However I do not get any posts listet but rather just one link referring to the subpage the gallery should be on. Could anyone help me out please?

Here is my code which is saved as page-gallery.php in my childthemes folder:

Read More
<?php get_header(); ?>
<div id="main" class="wrapper">
<?php global $query_string; if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="gallery_image_container">
        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
            <div class="gallery_image_thumb">
                <?php the_post_thumbnail('thumbnail'); ?>
            </div>
            <h2><?php the_title(); ?></h2>
        </a>
    </div>
<?php endwhile; else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
<?php get_footer(); ?>

The CSS is the following:

.gallery_container {
    position: relative;
    float: left;
    width: 150px;
    height: 150px;
    border: 10px solid #CCC;
    margin: 20px;
}

I have created a jsfiddle to tell you what I want to achieve in the end: http://jsfiddle.net/vdpktLxr/

Related posts

Leave a Reply

1 comment

  1. Your code just echos the content of your page “page-gallery.php” . For displaying POSTS you need to use another loop, for example something like this:

     <?php
     // The Query
     query_posts( $args );
    
     // The Loop
     while ( have_posts() ) : the_post();
         echo '<li>';
         the_title();
         echo '</li>';
     endwhile;
    
     // Reset Query
     wp_reset_query();
     ?> 
    

    You can find more info here