douyao7390 2019-07-30 16:29
浏览 94
已采纳

显示英文字符而不是阿拉伯语 - WordPress


I am posting Hadiths in my website and i post it in 3 translations: Arabic, Urdu, English. In Hadith's page, where Hadiths are showing one by one, It's showing Arabic excerpt text.
See my web, Here is my Website link: IF Islam

See this screenshot: enter image description here

I want here to show English Hadith excerpt text instead of Arabic and Urdu.
Which PHP code will do this?
Please help

Here is the content.php code:

<div class="col-lg-8 col-md-6">
    <div class="card-body">
       <a href="<?php the_permalink(); ?>" class="">
           <h2 class="single_post_title h3-responsive text-primary mb-1"><?php the_title(); ?></h2>
       </a>
       <div class="blog_meta">
           <time class="blog_meta_posted_on grey-text"><?php the_time('F j, Y g:i a'); ?></time>
           <a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>" class="blog_meta_author grey-text"><?php the_author(); ?></a>
           <a href="<?php the_permalink(); ?>#responses" class="blog_meta_count_comments grey-text"><?php echo get_comments_number(); ?> Comments</a>
           <label class="blog_meta_tags_list">
                <?php echo get_the_tag_list( '', ', ', '' ); ?>
           </label>
       </div>
       <div class="blog_excerpt_content black-text m-0 mt-2">
           <?php the_excerpt(); ?>
       </div>
       <a href="<?php the_permalink(); ?>" class="btn btn-primary">Read More</a>
    </div>
</div>
  • 写回答

2条回答 默认 最新

  • doudong2149 2019-07-31 18:28
    关注

    Try to replace

    <?php the_excerpt(); ?>
    

    With

    <?php
    $position = strpos(get_the_content(), 'Hadith in English Translation');
    $excerpt = strip_tags(substr(get_the_content(), $position));
    echo $excerpt;
    ?>
    

    I think get_the_content() returns the post full contents in HTML. We constructed a new $excerpt starting from 'Hadith in English Translation' to the end of the post contents using the functions strpos and substr. We also stripped the excerpt from any HTML tags using strip_tags.

    Of course you need to use the code only for the Hadith category (inside the "category-hadith.php" you added?) since you only need the modification there.

    Check if it is working and note that the solution supposes that the post contents has always the string 'Hadith in English Translation' and the english translation comes in last position after the two others.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备