I introduced you to "The whole process of WordPress theme production (7): Making sidebar.php". This article continues to introduce to you how to make index.php. Let's take a look. ~
We have already created sidebar.php, footer.php and header.php for all public pages of the blog. Starting today, we will create separate pages. Now what we want to create is the index page index.php. Here we can temporarily understand it as the home page, but in fact it is not as simple as the home page.
The main page is the article list, which lists the articles on your blog one by one. You may have noticed that the style of each article on the homepage is the same, but the text content such as title, time, author, and abstract are different, huh! We only need the HTML code of one article to make index.php. We don't need to manually write the HTML of so many articles. Moreover, this is not dynamic content. We only need one loop to display all articles on the home page. A loop is to do something repeatedly. The loop here is to repeatedly output articles. If you have learned any computer programming language before, it is not difficult to understand what a loop is, and the functions of a loop can be easily understood, such as while, for, foreach...
在Insert a sentence here, if you really want to know how to make a theme, please open the text editor, follow me step by step, modify step by step, refresh your blog every time you make a modification to see what changes, so Only then can you deepen your understanding. If you're too lazy to do it, I suggest you don't read the following content, as it won't be of much help to you.
Now start making index.php. Initially, there are three articles in index.php. When you open index.php, you can see the three tags of the article . Now we will delete the codes of the two articles, leaving one article and remove the article abstract. The modified code is like this:
The html skeleton of articles with different themes is different. If you are familiar with html, You can quickly identify the skeleton of the article. The above is the skeleton of our theme. Based on this, we will add dynamic content to index.php:
1. Add article title
Found:
Loreum ipsium massa cras phasellus
Changed to:
Here are the explanations of these php functions:
- Output the URL link of the article
- Output the title of the article
2. Add article tags
Many of us like to add some tags when writing articles, and we have also added a "tag cloud" to the sidebar, our theme Tags should be supported. Found:
Changed to:
Function reference: the_tags
3. Add date
Found: 31st Sep, 09
Changed to:
Function reference: the_time
About Y in this function For the date format obtained by n j, you can refer to the document (Chinese) and choose the time format you like: zh-cn: Custom time and date
Maybe you have read the time and date documents provided above, or If you are confused, here are a few examples. You can almost follow the example and specify the time and date format you like:
PHP code | Output content |
May 1, 1999 | |
May 01, 1999 | |
< ?php the_time('Y-m-d') ?> | 1999-05-01 |
99-05-01 02:09:08 |