在 WordPress 中创建 AZ 列表索引时出现重音问题

发布于 2025-01-19 11:14:41 字数 1150 浏览 2 评论 0原文

我为WordPress词典网站创建了一个AZ索引。 当一些字母上使用重音时,我有一个问题。

我用消毒来避免这种情况,但是现在每个用e开始的单词都像另一个字母,而不是被分组。我如何将每个单词从e开始,无论是否有口音?

这是指向我页面的链接: http://preprod2.atelier-labotte.fr/dictionnaire/dictionnaire/

这是我用于创建索引的代码:

<?php

    $letter = '';
    while($dictionnaire->have_posts())
    {
        $dictionnaire->the_post();

        // Check the current letter is the same that the first of the title
        if($letter != strtoupper(get_the_title()[0]))
        {

            echo ($letter != '') ? '</div></section>' : '';
            $letter = strtoupper(substr(sanitize_title( get_the_title() ),0,1));
            
            echo '<section id="'. $letter .'" class="wp-block-group letter-section"><div class="big-letter"><p>'.strtoupper(substr(sanitize_title( get_the_title() ),0,1)).'</p></div><div class="wp-block-group__inner-container d-grid columns-3">';   
         
        } 
?>

感谢您的帮助!

PS:我是非英语的母语者,请原谅我的误解!

I created an A-Z index for my wordpress dictionary website.
I've got an issue when accents are used on some letters.

I used sanitize to avoid this but now every word beggining with an E is like another letter instead of being grouped. How can I group every word begining with an E regardless of is there an accent or not ?

Here's the link to my page : http://preprod2.atelier-labotte.fr/dictionnaire/

Here's the code I used for creating the index :

<?php

    $letter = '';
    while($dictionnaire->have_posts())
    {
        $dictionnaire->the_post();

        // Check the current letter is the same that the first of the title
        if($letter != strtoupper(get_the_title()[0]))
        {

            echo ($letter != '') ? '</div></section>' : '';
            $letter = strtoupper(substr(sanitize_title( get_the_title() ),0,1));
            
            echo '<section id="'. $letter .'" class="wp-block-group letter-section"><div class="big-letter"><p>'.strtoupper(substr(sanitize_title( get_the_title() ),0,1)).'</p></div><div class="wp-block-group__inner-container d-grid columns-3">';   
         
        } 
?>

Thanks for your help !

PS : I'm non-english native speaker, please forgive my mistkakes !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撞了怀 2025-01-26 11:14:41

感谢您的帮助 !

我找到了达到所需物品的方法,因此我共享解决方案。
我希望这是实现这一目标的最简单方法,但这是我使用的:

<?php
$letter = '';
while($dictionnaire->have_posts())
{
    $dictionnaire->the_post();

    // Check the current letter is the same that the first of the title
    if($letter != strtoupper(sanitize_title(mb_strtoupper(mb_substr(get_the_title(), 0,1 , 'UTF-8')))))
    {

        echo ($letter != '') ? '</div></section>' : '';
        $letter = strtoupper(sanitize_title(mb_strtoupper(mb_substr(get_the_title(), 0,1, 'UTF-8'))));
        
        echo '<section id="'. $letter .'" class="wp-block-group letter-section"><div class="big-letter"><p>'.$letter.'</p></div><div class="wp-block-group__inner-container d-grid columns-3">';            
    } 
?>

Thanks for your help !

I find a way to reach what I needed so I share the solution.
I hope this is the simplest way to achieve this but here's what I used :

<?php
$letter = '';
while($dictionnaire->have_posts())
{
    $dictionnaire->the_post();

    // Check the current letter is the same that the first of the title
    if($letter != strtoupper(sanitize_title(mb_strtoupper(mb_substr(get_the_title(), 0,1 , 'UTF-8')))))
    {

        echo ($letter != '') ? '</div></section>' : '';
        $letter = strtoupper(sanitize_title(mb_strtoupper(mb_substr(get_the_title(), 0,1, 'UTF-8'))));
        
        echo '<section id="'. $letter .'" class="wp-block-group letter-section"><div class="big-letter"><p>'.$letter.'</p></div><div class="wp-block-group__inner-container d-grid columns-3">';            
    } 
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文