The WordPress Loop

Word Press Loop

The WordPress loop is the built-in tool used to allow you to get posts from your WordPress database and display them to your website / screen through a WordPress theme template file. The WordPress loop is a powerful tool that controls the display of the posts, you can display a list of posts by a specific author, date, title and category. The loop is PHP code that is placed within your chosen themes index.php page and can be easily edited and updated to display the details of your posts.

The code will not update if there is an error within your code, I found that from assessment 2 that  the WordPress theme I chose only wanted 1 set of opening and closing php tags and all code had to sit between the opening and closing tags <?php  ?>

 The have_posts  () checks to see if there are any posts and post them to your site.  while ( have_posts () )  : the_post(); this will display all the posts that have been written. By adding in some conditions into the loop we can start to filter out things like date and author by adding the_author into the php code will display the author of each post.

 

What is the function of a WordPress template?

WordPress Template

The function of the WordPress page template allows you to build and customize your own web pages, every page template has a template name. Page templates can change the design and layout of a page and can be applied to a single page or be used globally across all pages. Page templates may also display a block of content.  Page templates display your website’s images and words as dynamic content across your website. It can control the look and feel of individual pages and can apply to a single page, a page section or a class of pages.  It will also allow you to show an image that links to another part or post on your WordPress website. The pages templates also enable you to start to customize each individual section of each page. You can also create your own templates and apply it across as pages, navigation systems, main content areas and the footers. All template files live within a theme and show how a site is displayed, they contain a mixture of HTML and PHP code.

Template tags are a custom built-in function into WordPress and are used to get certain chunks of content such as the header and the footer. Instead of copying and pasting the footer content code across all pages by adding to the index.php file the code of get_footer() within the PHP code. If you make a change to your footer file, it updates globally across all of your template pages within your site.