Wordpress Tutorial: Add the time display of the day, month, day and week to the website

 Watson Blog September 15, 2017 00:26:52 WordPress comment two hundred and ninety-six Reading mode

Method 1: PHP

Add the code to the place you want to display

  1. <div? class = "lefttoptime" >
  2. ?????<? php? echo ? "&nbsp;" ?.? date ('MM/DD/YY ');??>
  3. ?????<? php? $weekarray = array ( Day , One , "Two" , Three , Four , Five , Six );? echo ? Week . $weekarray [ date ( "w" )];??>
  4. ?????</ div>

You can beautify and modify according to your favorite CSS style. It's OK not to add. Add the code to style.css in the current theme directory.

  1. .lefttoptime? {
  2. ???? margin:?0px?0px?0px?10px;
  3. ???? float:?left;
  4. ???? font-size:?14px;
  5. }

Method 2: Use js to implement

Add the following code to the position you want.

  1. <script? language= "Javascript" ? type= "text/javascript" >
  2. <!--
  3. var ? enabled?=?0;?today?=? new ? Date();
  4. var ? day;? var ? date;
  5. if (today.getDay()==0)? day?=? "? Sunday"
  6. if (today.getDay()==1)? day?=? Monday
  7. if (today.getDay()==2)? day?=? Tuesday
  8. if (today.getDay()==3)? day?=? "? Wednesday"
  9. if (today.getDay()==4)? day?=? Thursday
  10. if (today.getDay()==5)? day?=? Friday
  11. if (today.getDay()==6)? day?=? Saturday
  12. date?=? (today.getFullYear())?+? Year ?+? (today.getMonth()?+? 1?)?+? Month ?+? today.getDate()?+? Day ?+? day?+ "" ;
  13. document.write(date);
  14. //?-->
  15. </script>

Attachment:

This blog uses the robin theme. For example, the effect of this blog is added in the upper left corner begin/inc/user/user-profile.php Medium. As shown in the figure below:

wordpress教程:给网站添加当天年月日星期的时间显示

design sketch:

wordpress教程:给网站添加当天年月日星期的时间显示

 

 Watson Blog
  • This article is written by Published on September 15, 2017 00:26:52
  • This article is collected and sorted by the website of Mutual Benefit, and the email address for problem feedback is: wosnnet@foxmail.com , please keep the link of this article for reprinting: https://wosn.net/550.html

Comment