循环浏览 WordPress 帖子
我正在尝试获取 WordPress 帖子,一次 3 个,这是我正在使用的代码:
<?php while ( have_posts() ) : the_post() ?>
<?php if(get_post_meta($post->ID, 'feature', true) != true) {; ?>
<div class="show_col">
<?php for ($i = 1; $i <= 3; $i++) { ?>
<div class="set">
<a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'your-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark">
<img class="image" src="http://localhost/portpress/wp-content/themes/myTemp/portfolio/<?php echo get_post_meta($post->ID, 'intro_thump', true); ?>.jpg" width="300px" alt="AUREL #<?php the_ID(); ?>" />
</a>
<?php the_content("<P class='more'> Read More » </p>"); ?>
</div>
<?php }; ?>
</div>
<?php }; ?>
<?php endwhile; ?>
我知道这个循环正在回显一篇帖子三次 - 但我真正想要的是这个最终结果,
<div class="show_col">
<div class="show_col"> post1 </div>
<div class="show_col"> post2 </div>
<div class="show_col"> post3 </div>
</div>
<div class="show_col">
<div class="show_col"> post4 </div>
<div class="show_col"> post5 </div>
<div class="show_col"> post6 </div>
</div>
<!-- and so on -->
我这样做的高度每个帖子都有所不同 - 因此我添加了类似的内容 .show_col{clear:both} 这样接下来的三篇文章就可以放在下面
我希望你能帮忙
谢谢
i am trying to get wordpress posts, 3 at a time, this is the code i'm using:
<?php while ( have_posts() ) : the_post() ?>
<?php if(get_post_meta($post->ID, 'feature', true) != true) {; ?>
<div class="show_col">
<?php for ($i = 1; $i <= 3; $i++) { ?>
<div class="set">
<a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'your-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark">
<img class="image" src="http://localhost/portpress/wp-content/themes/myTemp/portfolio/<?php echo get_post_meta($post->ID, 'intro_thump', true); ?>.jpg" width="300px" alt="AUREL #<?php the_ID(); ?>" />
</a>
<?php the_content("<P class='more'> Read More » </p>"); ?>
</div>
<?php }; ?>
</div>
<?php }; ?>
<?php endwhile; ?>
i know this loop is echoing ONE post THREE times - but what i really want is this end result
<div class="show_col">
<div class="show_col"> post1 </div>
<div class="show_col"> post2 </div>
<div class="show_col"> post3 </div>
</div>
<div class="show_col">
<div class="show_col"> post4 </div>
<div class="show_col"> post5 </div>
<div class="show_col"> post6 </div>
</div>
<!-- and so on -->
i am doing this as the height of each post varies - therefore i add something like
.show_col{clear:both} so that the next three posts go under neath
i hope you could help
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是您需要的代码(我更正了您的一些语法):
另外,您似乎在关闭函数后添加了分号(
};
),不要这样做,没有必要。This is the code you need (I corrected some of your syntax):
Also you seem to add a semicolon after closing the function (
};
), don't do that, there is no need for it.