这是由Thesis提供支持的Wordpress网站。我想做的是在特色帖子区域中填入我在“特色/特色2”类别中放置的所有帖子。

这是PHP

function custom_featured_box() {
    if(is_home()) {
?>
<div id="featuredbox" class="clearfix">
        <?php $my_query = new WP_Query('category_name=featured&showposts=1');
        while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID;
        ?>
            <div id="featuredbox-main" style="background: url(<?php the_post_thumbnail('featured') ?>) no-repeat;">
                <a href="<?php the_permalink() ?>"><?php the_title() ?></a>
            </div>
            <?php endwhile; ?>
        <?php $my_query = new WP_Query('category_name=featured2&showposts=3');
        while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID;
        ?>
            <div id="featuredbox-secondary">
                <div class="secondary-item" style="width: 205px; background: url(<?php the_post_thumbnail() ?>) no-repeat;">
                    <a href="<?php the_permalink() ?>"><?php the_title() ?></a>
                </div>
            </div>
        <?php endwhile; ?>
    </div>
<?php
} }


“新的WP_Query”功能只是调用类别“ featured”和“ featured2”(
这是CSS:

.custom #feature_box { padding:0em; }

.custom #featuredbox { padding: 8px 0 10px 0;}
.custom #featuredbox-main {overflow: hidden; width: 650px; height: 225px; border: solid
1px #ccc; margin: 0 0 10px 0; position: relative;}
.custom #featuredbox-main a:hover {text-decoration: underline;}
    .custom #featuredbox-main a {z-index: 1; position: absolute; top: 121px; min-
height: 35px; left: 0; font-size: 20px; font-weight: bold; color: #fff; padding: 15px
10px; width: 100%; background: url(http://location-of-the-background-here);}

.custom #featuredbox-secondary {height: 162px; overflow: hidden; width: 650px;}
    .custom .secondary-item {margin-right: 10px; position: relative; border: solid 1px
#ccc; height: 160px; float: left; overflow: hidden;}
    .custom .secondary-item a:hover {text-decoration: underline;}
    .custom .secondary-item a {z-index: 1; position: absolute; top: 52px; left: 0;
font-size: 12px; font-weight: bold; color: #fff; padding: 8px 10px; width: 185px;
background: url(http://location-of-the-background-here);}


我不明白CSS为什么不将#featuredbox-secondary帖子放置为彼此相邻。

任何帮助将不胜感激。

附言这是当前代码的屏幕快照,希望它可以帮助人们理解我的意思。 http://img43.imageshack.us/img43/3011/csshelp.jpg

最佳答案

如果我对您的理解正确,那么您是否希望在div内,ID为“ featuredbox-secondary”的div中的每个带有“ secondary-item”类的div都紧挨着浮动?如果是这样,则需要将float声明应用于“ secondary-item”类。

10-01 14:10