i am using ACF to display an internationalized date with this code :
<?php
$dateformatstring = "l j F Y";
$unixtimestamp = strtotime(get_field('date'));
?>
<?php echo date_i18n($dateformatstring, $unixtimestamp); ?>
but i wish i could separate each part into span for example to obtain a result like this :
<span>*day number*</span><span>*week day*</span><span>*month*</span><span>*year*</span>
but despite many attemps, i couldn't make it -_- Thanks for your help ;-)
i am using ACF to display an internationalized date with this code :
<?php
$dateformatstring = "l j F Y";
$unixtimestamp = strtotime(get_field('date'));
?>
<?php echo date_i18n($dateformatstring, $unixtimestamp); ?>
but i wish i could separate each part into span for example to obtain a result like this :
<span>*day number*</span><span>*week day*</span><span>*month*</span><span>*year*</span>
but despite many attemps, i couldn't make it -_- Thanks for your help ;-)
Share Improve this question asked Nov 14, 2018 at 19:17 studiok7studiok7 236 bronze badges 2 |2 Answers
Reset to default 2thanks to @kero, i managed to do something like this :
<?php
$dayNumber = "l";
$weekDay = "j";
$month = "F";
$year = "Y";
$unixtimestamp = strtotime(get_field('date'));
?>
<?php echo '<span>' . date_i18n($dayNumber, $unixtimestamp) . '</span>'; ?>
<?php echo '<span>' . date_i18n($weekDay, $unixtimestamp) . '</span>'; ?>
<?php echo '<span>' . date_i18n($month, $unixtimestamp) . '</span>'; ?>
<?php echo '<span>' . date_i18n($year, $unixtimestamp) . '</span>'; ?>
Not sure it is the best way to do it but it works. Thanks !
There's another way to do it as demonstrated here:
- In ACF settings, use 'Custom Format' to separate the items you want to add HTML to with a comma
M,d
- In your output file, set up your date output as a variable
$date = get_field(‘date’);
- Next,
explode
the variable you created$dateArray = explode(‘,’, $date)
- Use the array you created to add HTML to each piece of your date
<p class="month"><?php echo $dateArray[0]; ?></p>
<p class="date"><?php echo $myArray[1]; ?></p>
- Profit!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744712616a4589431.html
echo '<span>'.date_i18n('..', $timestamp).'</span><span>'.date_i18n(...
(you get the idea) ? – kero Commented Nov 14, 2018 at 19:36