简体   繁体   English

如何显示四个彼此对齐的类别帖子? -WordPress的

[英]How do I display four category posts that align next to each other? - Wordpress

I'm trying to pull the 4 most recent posts from category "3" to be displayed within a 1000px div, but have each single post display in a 280px div and have them displayed inline. 我正在尝试从类别“ 3”中提取4个最新帖子,以在1000px div内显示,但每个帖子均以280px div显示,并以内嵌方式显示。

Right now, my code pulls the recent posts, but only styles the one most recent post. 现在,我的代码提取了最近发布的帖子,但仅设置了最近发布的帖子的样式。

Here is the current URL: http://dylanpolniak.com/clients/c&c/ Here is my code: 这是当前的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>

Try putting you class div inside of the while loop, and you have you #posts div unclosed. 尝试将class div放入while循环内,然后#posts div未关闭。

Change your code like this: 像这样更改代码:

<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!

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

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