我在wordpress网站上使用自定义php代码翻译日期格式,使用get\\u the\\u time。我必须在我的网站上的不同空间使用此代码,有时在一个页面上不止一次。
以下是我的代码,我将在需要时添加到自定义页面模板中:
<?php
$date = get_the_time(\'l j F Y\');
$interdit = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday","Sunday","January","February","March","April","May","June","July","August","September","October","November","December");
$replace = array("Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado","Domingo", "Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
$date_espagnole = str_replace($interdit, $replace, $date);
echo ($date_espagnole);
?>
我想知道的是,我怎样才能只声明一次这段代码,也许是在我的函数中。php,然后在需要时添加以下代码:
<?php echo ($date_espagnole);?>
以下是我在函数中尝试的内容。php:
function date_translation(){
$date = get_the_time(\'l j F Y\');
$interdit = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday","Sunday","January","February","March","April","May","June","July","August","September","October","November","December");
$replace = array("Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado","Domingo", "Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
$date_espagnole = str_replace($interdit, $replace, $date);
return $date_espagnole;
}
然后在需要时在我的自定义页面中:
<?php date_translation();?>
但它不起作用。有可能做到这一点吗?如果是,我做错了什么?
非常感谢您的帮助,