当语言为阿拉伯语时,Get_the_Date()返回英语年和日

时间:2020-02-18 作者:Delowar Hosain

我现在把WordPress语言改成了阿拉伯语get_the_date() 退货يناير 30, 2020 (半阿拉伯语和半英语)但我需要获得完整的阿拉伯语日期,如:يناير ٣٠, ٢٠٢٠

我该怎么做?

2 个回复
SO网友:rajat.gite

WordPress有date_i18n 根据时间戳以本地化格式检索日期。

尝试:

echo date_i18n("d F Y (H:i)",$date) ;

SO网友:rajat.gite

如果其他人需要此功能,这两个功能将以阿拉伯语显示wordpress网站的发布日期和时间:

日期:

功能。php

function single_post_arabic_date($postdate_d,$postdate_d2,$postdate_m,$postdate_y) {
    $months = array("Jan" => "يناير", "Feb" => "فبراير", "Mar" => "مارس", "Apr" => "أبريل", "May" => "مايو", "Jun" => "يونيو", "Jul" => "يوليو", "Aug" => "أغسطس", "Sep" => "سبتمبر", "Oct" => "أكتوبر", "Nov" => "نوفمبر", "Dec" => "ديسمبر");
    $en_month = $postdate_m;
    foreach ($months as $en => $ar) {
        if ($en == $en_month) { $ar_month = $ar; }
    }

    $find = array ("Sat", "Sun", "Mon", "Tue", "Wed" , "Thu", "Fri");
    $replace = array ("السبت", "الأحد", "الإثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة");
    $ar_day_format = $postdate_d2;
    $ar_day = str_replace($find, $replace, $ar_day_format);

    header(\'Content-Type: text/html; charset=utf-8\');
    $standard = array("0","1","2","3","4","5","6","7","8","9");
    $eastern_arabic_symbols = array("٠","١","٢","٣","٤","٥","٦","٧","٨","٩");
    $post_date = $ar_day.\' \'.$postdate_d.\' \'.$ar_month.\' \'.$postdate_y;
    $arabic_date = str_replace($standard , $eastern_arabic_symbols , $post_date);

    return $arabic_date;
}
<date>
<?php
  $postdate_d = get_the_date(\'d\');
  $postdate_d2 = get_the_date(\'D\');
  $postdate_m = get_the_date(\'M\');
  $postdate_y = get_the_date(\'Y\');                                

 echo single_post_arabic_date($postdate_d,$postdate_d2, $postdate_m, $postdate_y);
?>
</date>
时间:

功能。php

function single_post_arabic_time($posttime_h, $posttime_i, $posttime_a) {

    $ampm = array("AM", "PM");
    $ampmreplace = array("ق.ظ", "ب.ظ");
    $ar_ampm = str_replace($ampm, $ampmreplace, $posttime_a);

    header(\'Content-Type: text/html; charset=utf-8\');
    $standardletters = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
    $eastern_arabic_letters = array("٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩");
    $post_time = $posttime_h . \':\' . $posttime_i." ".$ar_ampm;
    $arabic_time = str_replace($standardletters, $eastern_arabic_letters, $post_time);

    return $arabic_time;
}
<time>
<?php
  $posttime_h = get_the_date(\'h\');
  $posttime_i = get_the_date(\'i\');
  $posttime_s = get_the_date(\'d\');
  $posttime_a = get_the_date(\'A\');

echo single_post_arabic_time($posttime_h,$posttime_i,$posttime_a);
?>
</time>

相关推荐

WordPress将添加过滤器添加到POST_DATE

我使用了一个插件,它可以让帖子等更新到Persian Date 但问题是,我只想转换前面的日期,而不是管理面板等。我发现该部分执行以下操作:add_filter(\'date_i18n\', \'ztjalali_ch_date_i18n\', 111, 4); It使用add_filter 在上执行此操作date_i18n 函数,我可以改变它吗date 在前面的博客帖子中。我不是wordpress专家,也不太了解date_i18n, 但我认为它指的是所有的post日期,所以我可以将代码更改为只