免责声明这不是一个完整的答案,因为我真的无法处理我不知道的迹象。这会帮助你找到正确的方向。
我的(基本)解决方案取自StackExchange, 我为您的functions.php
:
function ArabicDate( $time = false ) {
if ( $time === false ) {
$time = current_time( \'timestamp\' );
}
$months = array("Jan" => "يناير", "Feb" => "فبراير", "Mar" => "مارس", "Apr" => "أبريل", "May" => "مايو", "Jun" => "يونيو", "Jul" => "يوليو", "Aug" => "أغسطس", "Sep" => "سبتمبر", "Oct" => "أكتوبر", "Nov" => "نوفمبر", "Dec" => "ديسمبر");
$your_date = date( \'y-m-d\', $time ); // The Date calculated from the $time variable
$en_month = date("M", $time );
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 = date(\'D\', $time); // The Current Day
$ar_day = str_replace($find, $replace, $ar_day_format);
$standard = array("0","1","2","3","4","5","6","7","8","9");
$eastern_arabic_symbols = array("٠","١","٢","٣","٤","٥","٦","٧","٨","٩");
// use this line to format your arabic date
$current_date = $ar_day.\' \'.date( \'d\', $time ).\' / \'.$ar_month.\' / \'.date( \'Y\', $time );
$arabic_date = str_replace($standard , $eastern_arabic_symbols , $current_date);
return $arabic_date;
}
这不是最好的解决方案,因为您必须硬编码阿拉伯日期的时间格式。我很想做得更好,但我不知道如何确认这些标志的输出是否正确。
改变$ar_month
到date( \'m\', $time )
例如,如果希望月份是数字,而不是文本中的月份。
之后,您可以使用以下代码过滤日期函数:
add_filter( \'get_the_date\', \'f711_convert_to_arabic_date\', 10, 3 );
function f711_convert_to_arabic_date( $the_date, $d, $post ) {
$posttime = strtotime( $post->post_date );
return ArabicDate( $posttime );
}
现在你的模板标签(
get_the_date()
和
the_date()
) 回显或返回您的阿拉伯日期。
如果您想在模板中使用它,只需调用echo ArabicDate()
当前时间,或echo ArabicDate( $timestamp )
任何阿拉伯日期。