The Wordpress template: Components of a page

The elements that make up a page in Wordpress are small predefined part of code, represented by a function call in PHP.
Like Lego bricks, they can be assembled to compose the interface chosen by the author of the theme.

Main loop

The main loop display a post or a list of post or excerpts of last posts.

Start of loop

 if (have_posts()) : while (have_posts()) : the_post(); 

Displays one or more items. The number is defined in the administration panel.

End of loop

endwhile;  else:
_e('Sorry, no posts matched your criteria.');

_e is a function of the CMS and the argument string is translated by the localization module.



The parameters are in order:
- The display format. It depends on the country.
- The HTML code to put bafore. Example: <h4>
- The HTML to be placed after. Example: </ h4>
It is better not to indicate the format to allow the user of the template to configure it itself according to its country.



The arguments are in order:
- The separator. For example, a comma as above. Another example: '&bull;' for a round.
- Display mode: single or multiple for the class hierarchy if any.

The author


The author name is added on a collaborative website, otherwise it is superfluous. This function has no parameter.
And whether the authors have different websites, we can replace the link on the profile by a link on his website.


More options are described in the codex.

The title of the article


It is not part of the article, but is stored in a particular field in the database.
Optional arguments are:
- Before: HTML code to insert before the title, for example <h1>.
- After: HTML code to insert at end.

Example: the_title('<h1>', '</h1>');

Content of the post


The ___() argument is the text displayed when the content is cutted. It does not appear when the page is devoted to a single post. The text is translated automatically by the localization module.

More detail in the Wordpress documentation.



Displays everything concerning comments and can be deleted as a whole as well.

Navigation buttons


The following and previous articles.
One argument that is a string of parameters separated by &.
The values are:
- Before: HTML code to insert before.
- After: HTML code to insert after.

Edit button

 edit_post_link('Edit this entry.', '<p>', '</p>');

It is added inside the loop. The three optional arguments are:
- The label. For example, 'Edit'.
- HTML code to insert before.
- HTML code to insert after.

The button appears only when the reader has publishing rights.

The whole page format

The format of a full page for an article might look like this:


if(have_posts()): while (have_posts(): the post();

the title('<h1>', '<h1>');




See also