简体   繁体   English

将Wordpress帖子显示为带有标题的画廊

[英]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. 对于我正在从事的项目,我一直试图在子页面上设置wordpress发布循环,该循环将所有发布显示为缩略图,并在其下方显示发布标题。 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: 这是我的代码,在我的childthemes文件夹中另存为page-gallery.php:

<?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: CSS如下:

.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/ 我创建了一个jsfiddle来告诉您最终要实现的目标: http : //jsfiddle.net/vdpktLxr/

Your code just echos the content of your page "page-gallery.php" . 您的代码只是回显页面“ page-gallery.php”的内容。 For displaying POSTS you need to use another loop, for example something like this: 为了显示POSTS,您需要使用另一个循环,例如:

 <?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 您可以在这里找到更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM