我试图从类别“3”中拉出最近的4个帖子,以便在1000px div中显示,但每个帖子都显示在一个280px的div中并让它们以内联方式显示。
现在,我的代码会提取最近发布的帖子,但只会对最近发布的帖子进行设置。
以下是当前网址:http://dylanpolniak.com/clients/c&c/ 这是我的代码:
<div id="music">
<h1>Music</h1>
<div class="hr_dark"></div>
<div id="posts">
<?php query_posts('showposts=4&cat=3'); ?>
<div class="single_post">
<?php the_content(); if (have_posts()) : while (have_posts()) : the_post(); if ( has_post_thumbnail() ) {
// check if the post has a Post Thumbnail (featured image) assigned to it.
the_post_thumbnail(); the_title('<h4>', '</h4>');
} ?>
</div>
<?php endwhile; else : endif; ?>
<div class="hr_dark"></div>
<a href="music.php"><h2>View All</h2></a>
<style>
#posts { width: 1000px; margin: auto; }
.single_post { width: 280px; height: 400px; position: relative; display: inline-block; float: left; }
h4 { font-size: 20px; font-family: 'Satisfy', cursive; color: #202e31; text-align: center; font-weight: 400; }
</style>
答案 0 :(得分:2)
尝试将你的类div放在while循环中,然后让你#posts
div unclosed。
更改您的代码:
<div id="posts">
<?php query_posts('showposts=4&cat=3');
the_content(); if (have_posts()) : while (have_posts()) : the_post();
if(has_post_thumbnail() ) { ?>
<div class="single_post"> <?php
// check if the post has a Post Thumbnail (featured image) assigned to it.
the_post_thumbnail(); the_title('<h4>', '</h4>'); ?>
</div>
<?php
} ?>
</div> //add this closing div tag!