我希望能够单独设置每个WP帖子的样式,并且同时帖子循环自动将每个新帖子分配给自己的div。 例如:
<div id="blog-content-wp">
<div class="post">
Post 1
</div>
<div class="post">
Post 2
</div>
</div>
这是我到目前为止的代码:
<div id="blog-content-wp">
<?php while(have_posts()): the_post()?>
<?php $myposts = get_posts('');
foreach($myposts as $post) :
setup_postdata($post);
?>
<?php the_content(); ?>
<?php endforeach; wp_reset_postdata(); ?>
<?php endwhile;?>
<?php comments_template('', true);?>
</div>
所有这一切都是将我所有的帖子都放在blog-content-wp中,而我想要实现的只是每个帖子的单独div。
有什么建议吗? 我知道这可能是重复的,但到目前为止,我所看到的只是"如何为每个div获得三个帖子"等。
谢谢
在你的循环中打印出新的div,围绕着你对the_content()的调用
<div id="blog-content-wp">
<?php while(have_posts()): the_post()?>
<?php $myposts = get_posts('');
foreach($myposts as $post) :
setup_postdata($post);
?>
<div >
<?php the_content(); ?>
</div >
<?php endforeach; wp_reset_postdata(); ?>
<?php endwhile;?>
<?php comments_template('', true);?>
</div>
用postclass来做,给类提供标签,类等等
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php the_content(); ?>
</div>
完整参考:
http://codex.wordpress.org/Function_Reference/post_class