Skip to main content
We are Brand SEO Beijing serving international business, your marketing partner, Contact us by

Website production theme production article single page template single.php

In the previous tutorial, we have only done index.php. This file can be used as the home page, or as an archive page such as classification and tags. In this tutorial, let's make the specific page of the article - article single page template , if we don't have the single page template single.php, then the index.php file will be used instead, but for the article single page, we also need to add some other information, such as copyright statement, related articles, comments, etc., so we Another template should be made, there is already a single.php file under the theme folder we downloaded.You can try to delete this file, and then go to see the effect of displaying the article with index.php.
Open the single.php file under the theme folder with an editor. In the previous tutorial, we have replaced the header, bottom, and sidebar code in this file with the code to load the corresponding template.For a single page of an article, our article frame code page needs to be placed in a loop, but when it reaches a single page, it only loops once.So you can copy all the code in index.php, add and modify it.
The title of the article
Find the article title:

Loreum ipsium massa cras phasellus

Remember the code to get the article link and title that we talked about in the last tutorial?


XNUMX. Article tags:

News , Products

Change to


Change the date to:

The number of comments


Change to

XNUMX. Article content.
First delete the picture of the article and delete the following code:

/images/610x150.gif" alt=""/>

Then delete all the content of the article, namely: and the code between and replace it with:

XNUMX. Comment and return to the home page

<< Back to Blog Discuss this post

Change it to:

" class="button float" ><< Return to the home pageComment

Well, as mentioned earlier, the content page of the single page of the article needs to be placed in a loop statement (in fact, we need to execute the_post() function before the output article, which will generate the article variable $post).

Add the code behind, the effect:


then in the code


the front, pay attention. "Before" add code to complete the effect:

No articles!

The operation here is similar to the home page, but only one article needs to be output here, so it doesn’t matter whether the while is added or not. It should be reminded that if you add an if, you must have an endif, and if you add a while, you must have an endif. endwhile.
It may not be used in other syntaxes, in fact, you can also use {} here.for example:

The article single page creation method is completed.
Article source: WordPress theme making tutorial

Back to Top