我按照字母顺序排列帖子上面的第一个字母并且工作正常,但我需要显示一些斯拉夫字符,如ć,č,ž,đ...(UTF-8)。
这是代码:
<?php
$args = array(
'orderby' => 'title',
'order' => 'ASC',
'caller_get_posts' => 1,
'posts_per_page' => -1,
);
query_posts($args);
if (have_posts()) {
$curr_letter = '';
while (have_posts()) {
the_post();
$this_letter = strtoupper(substr($post->post_title,0,1));
if ($this_letter != $curr_letter) {
echo "<span>$this_letter</span>";
$curr_letter = $this_letter;
}
?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
<?php }
}
?>
我试过这个:
$this_letter = mb_strtoupper(mb_substr(apply_filters('the_title',$post->post_title),0,1));
$this_letter = mb_convert_encoding($letter,'UTF-8', mb_detect_encoding($this_letter) );
而不是:
$this_letter = strtoupper(substr($post->post_title,0,1));
但不起作用。
感谢您的帮助。
答案 0 :(得分:0)
这应该有效:
<?php
$args = array(
'orderby' => 'title',
'order' => 'ASC',
'caller_get_posts' => 1,
'posts_per_page' => -1,
);
query_posts($args);
?>
<?php
if (have_posts()) {
$curr_letter = '';
while (have_posts()) {
the_post();
$this_letter = strtoupper(mb_substr(mb_convert_encoding($post->post_title,'UTF-8'),0,1));
if ($this_letter != $curr_letter) {
echo "<span>$this_letter</span>";
$curr_letter = $this_letter;
}
?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
<?php }
}
?>