【发布时间】:2010-05-11 01:44:13
【问题描述】:
我正在为 WordPress 运行一个名为 Category Posts Widget 的插件:http://wordpress.org/extend/plugins/category-posts/
它使用一个while循环来显示某个类别中所有帖子的名称。我想得到它,以便在每秒输出的 li 标签上附加一个不同的类。
这是插件的代码块:
// Post list
echo "<ul>\n";
while ( $cat_posts->have_posts() )
{
$cat_posts->the_post();
?>
<li class="cat-post-item">
<a class="post-title" href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
<?php
if (
function_exists('the_post_thumbnail') &&
current_theme_supports("post-thumbnails") &&
$instance["thumb"] &&
has_post_thumbnail()
) :
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail( 'cat_post_thumb_size'.$this->id ); ?>
</a>
<?php endif; ?>
<?php if ( $instance['date'] ) : ?>
<p class="post-date"><?php the_time("j M Y"); ?></p>
<?php endif; ?>
<?php if ( $instance['excerpt'] ) : ?>
<?php the_excerpt(); ?>
<?php endif; ?>
<?php if ( $instance['comment_num'] ) : ?>
<p class="comment-num">(<?php comments_number(); ?>)</p>
<?php endif; ?>
</li>
<?php
}
echo "</ul>\n";
我只是想在输出列表中的每一秒都得到它,li 有一个不同的类,例如 cat-post-item-alt。
谢谢,
韦德
【问题讨论】:
标签: php wordpress plugins while-loop