我正在尝试从类别“3”中提取 4 个最新帖子以显示在 1000 像素的 div 中,但将每个帖子显示在 280 像素的 div 中并内联显示。
现在,我的代码提取最近的帖子,但只为最近的帖子设置样式。
这是当前的 URL: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>
最佳答案
尝试将类 div 置于 while 循环内,然后您的#posts
div 未关闭。
像这样更改您的代码:
<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!
关于php - 如何显示彼此相邻的四个类别帖子? - WordPress的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22119308/