How to customize Date Format in Wordpress

本小妞迷上赌 提交于 2019-12-13 07:03:21

问题


I need to customize the date format in Wordpress. I know that minor date changes can be made from Dashboard << Settings << General << Date. But my needs are not fulfilled from that.

I need that on post page, Month should have different font style and Day with a different font.


回答1:


If I'm understanding your question correctly, one solution would be to wrap each part of the date in a different span class. So whenever you want to insert the date you would use something like the following:

<?php the_time('F', '<span class="month">', '</span>'); ?>
&nbsp;
<?php the_time('d', '<span class="day">', '</span>'); ?>

Then you can target these different span classes separately in your css.

.month {
    font-family:serif;
}
.day {
    font-family:sans-serif;
}

This will output a format that looks like this: April 11 where both the month and date can be styled separately however you want. You can display a different month/date format by changing what you pass into the_time() function. For example, changing the month code to <?php the_time('m', '<span class="month">', '</span>'); ?> will output Apr 11 instead.

There are a lot of different configurations for this and there's more info on that here http://codex.wordpress.org/Formatting_Date_and_Time



来源:https://stackoverflow.com/questions/10100483/how-to-customize-date-format-in-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!