Hướng dẫn how do i get the date and time to show on wordpress? - Làm cách nào để hiển thị ngày và giờ trên wordpress?
Adding the date and time to the WordPress Loop seems like a simple enough task, right? Show Well, yes. It can be a case of coding a simple template tag and letting WordPress do the work for you. But sometimes you can run into problems along the way. In this quick tip, I'll show you the different functions WordPress gives you for displaying the date and time and tell you which ones to use if you run into snags. If you need a quick refresher on using PHP for WordPress, check out my free course on the topic. The Available Template TagsWordPress gives you four functions to output the date and/or time. These are:
Formatting the DateEach function has a default format, which you can override if you need to. To do this, you'll need to use standard PHP date and time formatting. Here are some examples, all for a post published on 20 November 2018.
Troubleshooting Dates in the Loop: Missing Dates in an Archive PageIf you are using Sometimes you might want to keep it like this, if you don't want to repeat the date for every post published that day. But if you want to ensure that all posts have their date output with the title and any other content you're outputting, you'll need to use another function. You can use any of the other three functions above. The simplest option is to replace
Note: If you're puzzled by the fact that
I had this problem in the front page template of a theme I coded for a client. In this template were a number of loops, all leading to different content types on the site and all coded using Here's the original code:
I edited the function so it read like this:
In the line beginning ', '' ); // The same thing can be achieved by writing the span tags around the get_the_date() and get_the_time() functions. echo ''.get_the_date( 'j F, Y').''; echo ''.get_the_time( 'j F, Y').''; ?>0. It fixed the problem. So if you ever find that dates aren't showing up in your archives, this might be the solution. Some Tips for Displaying the Date and TimeAs mentioned earlier in the article, you can use four different functions to output the publication date for posts on archive pages. Using the |