Lecture
Today we continue the theme of sub-templates, opened in the last lesson with examples of creating files header.php , sidebar.php and footer.php.
Now that the index.php file is divided into zones, everything will be much easier.
Before you perform the next operation, look at your sidebar, click on the Archive link. The opened page is no different from your main page, right? Now:
We created the file archive.php , and made it different from index.php , thus we customized the view of all Archive pages.
Now, when you refresh the archive page, only the summary will be displayed, not the full text of the posts.
Why do you need it? First, to diversify the design and be able to change the appearance of the pages depending on its functions, as well as to prevent punishment from Google and other search engines for duplicating content. If the two pages are exactly the same - this is duplicate content.
What if you have a private blog? Then, it is not necessary to create differences between the archive and main pages. But this does not mean that excerpts are not useful for private blogs.
Also - by default, your category pages will look for instructions on how to display content from the archive.php file . If you do not have archive.php, category pages will be searched in the index.php file .
If you want category pages to look different than the main page and archive pages, create a file category.php and give it the necessary parameters.
Now all search results will be displayed as a summary. Without the search.php file, the search function will access the index.php file to display the search results.
As needed, to recall the hierarchy of WordPress files, you can go back to lesson number 1.
I hope you remember that there is a difference between a Page and a page. The name is case sensitive. The page.php template defines the properties of those very special Pages.
First, in the page.php file , enter the following code immediately under ? >:
one
|
|
and
one
|
|
Secondly, remove the postmetadata code from page.php . This is what you should get without postmetadata .
one
2
3
four
five
|
|
Third, remove the posts_nav_link () or navigation block from page.php .
one
2
3
four
five
|
|
The first line of code was responsible for displaying links to sub-pages.
For example, edit the About Me page. Add the code to the page several times in a paragraph and see what happens. This is useful when you need to break a really long page into several smaller pages.
As for the second line of code, this is the post editing link, which is visible only to the administrator.
Blog pages cannot be included in categories, and since they are static, there is no need to display the date they were created, which is why you deleted postmetadata . Also, it is worth removing posts_nav_link () because it also works only for posts where links to the previous page and the next page are displayed.
Save and close the page.php file .
When you click on the post title to see all the material, you go to the view mode of a separate post. The single.php template is responsible for the appearance of the page containing the post.
In file single.php enter the following code under :
one
|
|
Yes, this is all the same line of code for links to sub-pages. Did you know that you can also split the post into several sub-posts?
After that, replace ?> on:
On the main page, as well as on archive pages, categories and search, you use the posts_nav_link () function to call up links to the previous and next pages. For the page where the post is displayed, there are no such links. Use the previous_post_link () and next_post_link () functions to call up links to the previous and next post.
Save the single.php file. Visit the viewing page of each individual post to see the difference in the navigation area between them.
Overview of the lesson covered
Everything is for today, and very soon we will publish the last lesson of the course “Creating WordPress Themes” and see what to do next :-) In the meantime, ask questions and express your wishes and suggestions in the comments!
Comments
To leave a comment
Content Management Systems (CMS)
Terms: Content Management Systems (CMS)