【发布时间】:2014-03-13 15:36:00
【问题描述】:
亲爱的 stackoverflow,有人可以帮助我解决这个问题,因为我花了超过 3 个小时试图修复它。下面的代码连续回显 2 个帖子,但我希望它连续 4 个。 感谢您的帮助:
第一个是我的content.php
<article id="post-<?php the_ID(); ?>" <?php post_class('group'); ?>>
<div class="post-inner post-hover">
<div class="post-thumbnail_id">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php if ( has_post_thumbnail() ): ?>
<?php the_post_thumbnail('thumb-medium'); ?>
<?php elseif ( ot_get_option('placeholder') != 'off' ): ?>
<img class="placeholder" src="<?php echo get_template_directory_uri(); ?>/img/thumb-medium.png" alt="<?php the_title(); ?>" />
<?php endif; ?>
</div>
</div>
</article>
index.php
<?php query_posts('category_name=content&showposts=2'); ?>
<?php if ( have_posts() ) : ?>
<div class="post-list group">
<div style="background:green; width:100%;">
<?php $i = 1; echo '<div class="post-row2">'; while ( have_posts() ): the_post(); ?>
<?php get_template_part('content'); ?>
<?php if($i % 2 == 0) {echo '</div><div class="post-row2"></div><div class="post-row2">';
}
$i++; endwhile; echo '</div>'; ?>
</div></div>
<?php endif; ?>
【问题讨论】:
-
您是否尝试过将每次出现的 2 更改为 4?小线索:category_name=content&showposts=4
-
是的,但没有成功:';而(有_posts()):the_post(); ?>'; } $i++;结束;回声''; ?>
-
你有 4 个帖子吗?
-
是的,我有 4 个帖子
-
它们属于正确的类别吗?例如'内容'
标签: php wordpress post categories