我有一个问题,我在wordpress中按标题升序显示帖子,但我想要的是显示帖子组的第一个字母,我的意思
是A: Annanas
Apple
Almond
B: Banana
G: Grape
我不知道如何在标准循环中实现这样的东西
<?php query_posts( array ( 'category_name' => 'publishers', 'orderby' => 'title', 'order' => 'ASC' ) ); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li>
<?php the_title(); ?>
</li>
<?php endwhile; endif; wp_reset_query(); ?>
如果有人能帮助我,我会很高兴...
保重,祝你有美好的一天!
一个想法是:
<?php
$letter=' ';
query_posts( array ( 'category_name' => 'publishers', 'orderby' => 'title', 'order' => 'ASC' ) );
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li>
<?php
$title=get_the_title();
$initial=strtoupper(substr($title,0,1));
if($initial!=$letter)
{
echo "<span>$initial : </span>";
$letter=$initial;
}
echo $title;
?>
</li>
<?php endwhile; endif; wp_reset_query(); ?>