繁体   English   中英

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

[英]Display Wordpress Posts as gallery with title

对于我正在从事的项目,我一直试图在子页面上设置wordpress发布循环,该循环将所有发布显示为缩略图,并在其下方显示发布标题。 但是我没有得到任何帖子列表集,而只有一个链接指向图库应位于的子页面。 有人可以帮我吗?

这是我的代码,在我的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(); ?>

CSS如下:

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

我创建了一个jsfiddle来告诉您最终要实现的目标: http : //jsfiddle.net/vdpktLxr/

您的代码只是回显页面“ page-gallery.php”的内容。 为了显示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();
 ?> 

您可以在这里找到更多信息

暂无
暂无

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

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