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:
<?php get_header(); ?>
<!-- Column 1 /Content -->
<div class="grid_8">
<!-- Blog Post -->
<div class="post">
<!-- Post Title -->
<h3 class="title"><a href="single.html">Loreum ipsium massa cras phasellus</a></h3>
<!-- Post Data -->
<p class="sub"><a href="#">News</a>, <a href="#">Products</a> • 31st Sep, 09 • <a href="#">1 Comment</a></p>
<div class="hr dotted clearfix"> </div>
<!-- Post Image -->
<img class="thumb" alt="" src="<?php bloginfo('template_url'); ?>/images/610x150.gif" />
<!-- Post Content -->
<!-- Read More Button -->
<p class="clearfix"><a href="single.html" class="button right"> Read More...</a></p>
</div>
<div class="hr clearfix"> </div>
<!-- Blog Navigation -->
<p class="clearfix"> <a href="#" class="button float"><< Previous Posts</a> <a href="#" class="button float right">Newer Posts >></a> </p>
</div>
<?php get_sidebar(); ?><?php get_footer(); ?>
Copy after login
As you can see from the above code, the html skeleton of an article is:
<div class="post">
<!-- Post Title -->
<h3 class="title"><a href="single.html">文章标题</a></h3>
<!-- Post Data -->
<p class="sub"><a href="#">标签1</a>, <a href="#">标签12</a> • 发布时间 • <a href="#">评论数</a></p>
<div class="hr dotted clearfix"> </div>
<!-- Post Image 文章的缩略图 -->
<img class="thumb" alt="" src="<?php bloginfo('template_url'); ?>/images/610x150.gif" />
<!-- Post Content -->
文章内容
<!-- Read More Button -->
<p class="clearfix"><a href="single.html" class="button right"> 阅读全文按钮</a></p>
</div>
<div class="hr clearfix"> </div>
Copy after login
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:
<h3 class="title"><a href="single.html">Loreum ipsium massa cras phasellus</a></h3>
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:
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:
The above is the detailed content of The whole process of WordPress theme creation (8): making index.php. For more information, please follow other related articles on the PHP Chinese website!
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
There is no perfect WordPress product registration plugin, the choice should be based on actual needs and website size. Recommended plug-ins include: MemberPress: powerful but high-priced, complex configuration Restrict Content Pro: Focus on content restrictions and member management, cost-effective Easy Digital Downloads: Sell digital products, and users register as additional functions
Reasons why WordPress websites cannot be found in search engines: 1. Indexing issues; 2. Content issues; 3. Website technical issues; 4. Link issues; 5. Other issues such as geographical restrictions, website name and social media presence.
A step-by-step guide to replacing a header image of WordPress: Log in to the WordPress dashboard and navigate to Appearance >Theme. Select the topic you want to edit and click Customize. Open the Theme Options panel and look for the Site Header or Header Image options. Click the Select Image button and upload a new head image. Crop the image and click Save and Crop. Click the Save and Publish button to update the changes.
How to turn off a comment in WordPress? Specific article or page: Uncheck Allow comments under Discussion in the editor. Whole website: Uncheck "Allow comments" in "Settings" -> "Discussion". Using plug-ins: Install plug-ins such as Disable Comments to disable comments. Edit the topic file: Remove the comment form by editing the comments.php file. Custom code: Use the add_filter() function to disable comments.
WordPress Error Resolution Guide: 500 Internal Server Error: Disable the plug-in or check the server error log. 404 Page not found: Check permalink and make sure the page link is correct. White Screen of Death: Increase the server PHP memory limit. Database connection error: Check the database server status and WordPress configuration. Other tips: enable debug mode, check error logs, and seek support. Prevent errors: regularly update WordPress, install only necessary plugins, regularly back up your website, and optimize website performance.
How to copy WordPress code? Copy from the admin interface: Log in to the WordPress website, navigate to the destination, select the code and press Ctrl C (Windows)/Command C (Mac) to copy the code. Copy from a file: Connect to the server using SSH or FTP, navigate to the theme or plug-in file, select the code and press Ctrl C (Windows)/Command C (Mac) to copy the code.
Enable comments in WordPress website: 1. Log in to the admin panel, go to "Settings" - "Discussions", and check "Allow comments"; 2. Select a location to display comments; 3. Customize comments; 4. Manage comments, approve, reject or delete; 5. Use <?php comments_template(); ?> tags to display comments; 6. Enable nested comments; 7. Adjust comment shape; 8. Use plugins and verification codes to prevent spam comments; 9. Encourage users to use Gravatar avatar; 10. Create comments to refer to
To log in to a WordPress website account: Visit the login page: Enter the website URL plus "/wp-login.php". Enter your username and password. Click "Login". Verification Two-step Verification (optional). After successfully logging in, you will see the website dashboard.