Styling the date format with date_i18n

I'm in wordpress, I am trying to format the date output. This code use to call the end of the sales promotion:<?

I'm in wordpress, I am trying to format the date output. This code use to call the end of the sales promotion:

<?php $thepostid = get_the_ID();
$sale_price_dates_to = ( $date = get_post_meta( $thepostid, '_sale_price_dates_to', true ) ) ? date_i18n( 'M j Y', $date ) : '';
echo '<div class="endsale">' .'<span>'.'Promo end ' . '</span>'.$sale_price_dates_to .'</div>';
?>  

It's output looks like this: JAN 21 2016

I need to style the date and need to give div or span to M, j and Y.

I'm not familiar PHP to get things working.

Can anyone help me?

Thank for any kind of help.

I'm in wordpress, I am trying to format the date output. This code use to call the end of the sales promotion:

<?php $thepostid = get_the_ID();
$sale_price_dates_to = ( $date = get_post_meta( $thepostid, '_sale_price_dates_to', true ) ) ? date_i18n( 'M j Y', $date ) : '';
echo '<div class="endsale">' .'<span>'.'Promo end ' . '</span>'.$sale_price_dates_to .'</div>';
?>  

It's output looks like this: JAN 21 2016

I need to style the date and need to give div or span to M, j and Y.

I'm not familiar PHP to get things working.

Can anyone help me?

Thank for any kind of help.

Share Improve this question edited Jul 19, 2019 at 19:27 Sami Ahmed Siddiqui 1293 bronze badges asked May 14, 2016 at 19:10 MailmulahMailmulah 971 gold badge4 silver badges13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Just use date_i18n in multiple places with PHP date arguments just for what you need:

if ( $date = get_post_meta( $thepostid, '_sale_price_dates_to', true ) ) {
    $sale_price_dates_to =
        '<span class="m">' . date_i18n( 'M', $date ) . '</span> ' .
        '<span class="d">' . date_i18n( 'j', $date ) . '</span> ' .
        '<span class="y">' . date_i18n( 'Y', $date ) . '</span>';
} else {
    $sale_price_dates_to = '';
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745310367a4621967.html

相关推荐

  • Styling the date format with date_i18n

    I'm in wordpress, I am trying to format the date output. This code use to call the end of the sales promotion:<?

    14小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信