[英]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.