Theme for Wordpress: The post page
The code of an article page is a combination of the HTML code of a page and several components natively provided by the Wordpress software.
We will detail it in two parts. First, the overall structure of the page of an article, that we put in the file single.php.
<html> <head></head> <body> <?php get_header(); ?> <?php the_post() ?> <div class="singlepost"> <h1 class="postitle"><?php the_title(); ?></h1> <div class="content"> <?php the_content(); ?> </div> </div> <?php get_sidebar() ?> <?php get_footer(); ?> </body> </html>
The function call: the_post () retrieves the contents of the last post, but it is the_content() which displays the text and the_tile() which displays the title, they are stored in different fields of the database.
In the same page are inserted the other files that correspond to the header, the footer, the side panels.
In practice, the page code as <html>, <head>, <body> are instead placed in the header.php file in order to reuse them in the home page (unless you want they are different). So get_header() is enough to integrate them.
Similarly </body> and </html> are placed in the footer.php file.
Detail for the body of the article
Now we see the various components providing information on article we deemed useful to readers.
<?php the_post() ?> <h1 class="postitle"><?php the_title(); ?></h1> <?php the_category(', ') ; the_content(); edit_post_link(); link_pages(); if (comments_open()) comments_template(); ?>
The order of elements is at the discretion of the author of the theme, and for the presentation, it depends entirely on the style sheet.
The ingredients are the edit button: edit_post_link (), the links on the next and previous page: link_pages (), and the comment block.
In fact we must also assign classes to each element to change its appearance through the style sheet:
<?php the_post() ?> <h1 class="postitle"><?php the_title(); ?></h1> <div class="cat"> <?php the_category(', ') ; ?></div> <div class="content"><?php the_content(); ?></div> <div class="edit"><?php edit_post_link(); ?> </div> <div class="links"><?php link_pages(); ?> </div> <div class="comments"> if (comments_open()) comments_template(); </div> ?>
Our article page is ready to be put online, and we have to define also a static page (which may be similar to it), and the home page that displays several posts or excerpts of the latest articles.
After the article may be displayed the list of recent posts, rather than on the sidebar.
The list is useless on the home page, so the page of an article is the best place to show it.
The page can use the components of articles and widgets to access the database.