2017-07-27 36 views
1

我想獲得只有一天和一個月的wordpress的自定義字段日期。我設法得到兩個,但我需要顯示不同變量的月份和日期。像:27JUL。這是我的代碼。如何從wordpress的自定義字段只獲取日期的日期和月份?

<?php 
    $time = strtotime(get_field('date')); 
    $date = date('M d', $time); 
    echo "$date"; 
?> 
+0

什麼是'get_field( '日')'的價值? – bhill77

+0

剛剛刪除'Y',因爲它表示爲年,拿出來,只是檢查你需要的[格式](http://php.net/manual/en/function.date.php) – Ghost

+0

用戶可以發佈新聞或博客日期。它是從日期選擇器中選擇的。 – Jklyn

回答

1

這是你的代碼:

<?php 
    $time = strtotime(get_field('date')); 
    echo '<span class="day">' . date('d', $time) . '</span><span class="month">' . date('M', $time) . '</span>'; 
?> 
0

試試這個代碼:

<?php 
$date = "2012-01-05"; 
$time=strtotime($date); 
$month=date("F",$time); 
$date=date("d",$time); 
?> 

<span class="day"><?php echo $month; ?></span><span class="month"><?php echo $date; ?></span> 
相關問題