advanced custom fields - html element to separate php variable strings - ACF datepicker

i am using ACF to display an internationalized date with this code :<?php$dateformatstring = "l j F Y";$uni

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
  • Why not just echo '<span>'.date_i18n('..', $timestamp).'</span><span>'.date_i18n(... (you get the idea) ? – kero Commented Nov 14, 2018 at 19:36
  • yes i get it ! :-) – studiok7 Commented Nov 14, 2018 at 19:44
Add a comment  | 

2 Answers 2

Reset to default 2

thanks 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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信