Wordpress时间日期函数-Date & Time Template Tags

在制作Wordpress主题时,其中很重要的一块就是如何定义日期时间的格式样式,须熟练掌握并灵活运用Wordpress日期时间函数。

<?php the_date_xml(); ?> 在文章中以YYYY-MM-DD格式显示日期, 例如(2004-09-24) ,无参数。

<?php the_date(‘format’, ‘before’, ‘after’, echo); ?>>  文章日期。

参数说明:

  • format :日期格式,默认值为你在Wordpress中设置的日期时间格式。
    例如:<?php the_date(‘n-j-Y’, ’before’, ’after’, echo); ?>。
  • before:日期前缀,默认值为空。
    例如:<?php the_date(‘format’, ’&raquo’, ’after’, echo); ?>。
  • after:日期后缀,默认值为空。
    例如:<?php the_date(‘format’, ’&raquo’, ’after’, echo); ?>。
  • echo:true|false ,如果echo=true的话就显示日期,否则返回PHP使用的日期。
    例如:<?php the_date(‘format’, ’before’, ’after’, TRUE); ?>。

<?php the_time(‘d’); ?> 显示文章发表的时间。

参数说明:

  • d:发表文章的时间格式。
     例如:<?php the_time(‘H:i:s’); ?>。

<?php the_modified_date(‘d’); ?>  显示文章最后修改的日期,默认值为你在Wordpress中设置的日期时间格式。

参数说明:

  • d:日期格式。
    例如:<?php the_modified_date(‘n-j-Y’); ?>。

<?php the_modified_time(‘d’); ?> 显示文章最后修改的时间,默认值为你在Wordpress中设置的日期时间格式。

参数说明:

  • d:时间格式。
    例如:<?php the_modified_time(‘H:i:s’); ?>。

<?php get_the_time(‘format’); ?>  返回供PHP使用的当前文章的时间,注:不会在文章中显示出来。

参数说明:

  • format:时间格式,默认值为你在Wordpress中设置的日期时间格式。
    例如:<?php get_the_time(); ?>。

<?php single_month_title(‘prefix’, display) ?> 返回当前文章发表的月份及年份,此函数只能在按日期归档的档案页面使用。

参数说明:

  • prefix:前缀。
    例如:<?php single_month_title(‘&bull’, display) ?>。
  • display:true | false。如果为true,则显示标题,否则返回供php使用的标题。
    例如:<?php single_month_title(‘prefix’, FALSE) ?>。

<?php get_calendar(); ?> 返回供PHP使用的当前文章的时间,注:不能在页面中显示出来。

参数说明:

  • initial:true | false,如果为true,则将天(day)缩写为一个字母,例如Sunday将会缩写为”S”, 否则会根据本地时间来缩写,例如”Sunday”可能会缩写为 “Sun”。
    例如:<?php get_calendar(false); ?>
除非注明,本博客文章均为原创,转载请以链接形式标明本文地址
原创文章如转载,请注明:转载自 任鸟飞网页设计 [ http://www.renniaofei.com/ ]
本文链接地址: http://www.renniaofei.com/code/wordpress-date-time-template-tags/
引用通告地址 Trackback URL:直接在本文链接地址后添加 trackback/
本文短网址: http://bit.ly/cjTEeM
任鸟飞

任鸟飞网页设计网创办者 主要关注网页设计,网站建设,图形图像设计。 Twitter @renniaofei QQ:29900684

留下评论

:wink: :-| :-x :twisted: :) 8-O :( :roll: :-P :oops: :-o :mrgreen: :lol: :idea: :-D :evil: :cry: 8) :arrow: :-? :?: :!: