banner



Where Are Pages 7 Templates Stored

Read Time: 10 mins Languages:

Just where does WordPress store your pages and posts, and how does it admission them?

Pages and posts are stored in the WordPress database. This is an essential function of how your WordPress site works. Without information technology, none of your pages or posts would be saved, and they wouldn't be displayed when someone visits them.

In this postal service, I'll testify you how the database in WordPress works and how WordPress builds a page from the database when a visitor comes to your site.

How WordPress Works: Database and Files

WordPress is a content management system (or CMS). This means that instead of creating a static HTML file for each page in your site, it uses a database to store all the content of those pages, and then uses code to admission that content each time a page is loaded.

As well as the database, WordPress consists of two more elements:

  • The cadre files that run WordPress itself, which you install when you prepare upwards your site.
  • Any files you upload to the site, including theme and plugin files besides as media attachments.

WordPress uses all these to build the pages in your site without yous having to write whatever code.

Let's take more of a look at where your pages and posts are stored and how the database is structured.

Where Posts and Pages Are Stored

All of the content in your site is stored in the database. This includes:

  • Your pages, posts, and whatsoever posts of a custom mail service type (eastward.g. products if you're running a store).
  • Data about attachments.
  • Any metadata such as post categories and tags (and custom taxonomies if yous accept them in your site), too as custom fields and any metadata added by plugins.
  • Information on the attachments you've uploaded to your site, including the proper name of the file, metadata such as alt text and a clarification, and information on which pages or posts fine art might be attached to.
  • Your settings, including overall site settings such as the site title and description, and more specific settings for your plugins and theme.
  • User data and settings.

There are 12 tables in the WordPress database, which you can meet in this epitome from the WordPress Codex.

the WordPress database the WordPress database the WordPress database

Most of the tables are linked to each other, with wp_posts being the well-nigh important one:

  • wp_posts is where the content of your posts and pages is stored. Information on attachments is also stored in this tabular array, every bit well as navigation menus and revisions.
  • wp_postmeta (linked to wp_posts) stores metadata near posts and pages.
  • wp_comments (linked to wp_users) stores all of the comments on your posts, including who they were posted by and when they were added.
  • wp_commentmeta (linked to wp_comments) stores metadata almost comments.
  • wp_terms (linked to wp_term_taxonomy) stores all the taxonomy terms in your site, including your categories and tags.
  • wp_term_taxonomy (linked to wp_terms and wp_term_relationships) stores the taxonomy for each term in the wp_terms table.
  • wp_term_relationships (linked to wp_terms_taxonomy and wp_posts) links your posts to the taxonomy terms that have been assigned to them.
  • wp_termmeta (linked to wp_terms) stores metadata on your taxonomy terms.
  • wp_users (linked to wp_posts and wp_comments) stores a list of all the users on your site and their username, countersign, and other information.
  • wp_usermeta (linked to wp_users) stores metadata on your users.

The relationships between the tables link all of the data and ensure that for a given post, WordPress knows what taxonomy terms it has, who wrote it, what comments it has, and more.

Ii tables aren't linked to the others and don't take a relationship to your posts:

  • wp_options stores global options and settings for the whole site (not for a post, which would be stored in wp_postmeta).
  • wp_links is a hangover to the early days of blogging and stores the contents of the blogroll, a list of links. Information technology'due south rarely used these days.

So your posts and pages are stored in wp_posts, just metadata about them is stored in other tables which are linked to them.

But how does WordPress translate all this data into pages on your site?

How WordPress Fetches Content for Your Pages

WordPress uses a specific piece of code called The Loop to fetch database content and output it in the pages of your site. This applies for unmarried pages, annal pages, the home page, and search results.

Watch this brusque video to go a complete introduction to the loop.

The loop starts with this code:

This checks if there are any posts to be output on this page, and while at that place are, information technology uses the_post() template tag so that the posts' content tin exist output.

Notation that here, "postal service" doesn't mean a web log post. A mail service in this context tin mean any content type, including a post, page, attachment, or post of a custom mail type. Information technology tin become confusing!

Information technology ends with this code:

This ends the while loop from the beginning, meaning that WordPress stops looping through posts when it'south plant everything it needs for this page in the site. It then closes the if check and stops checking if there are any posts.

In between those two lines will be the code that outputs content. I'll show you different versions of this for dissimilar content types shortly.

WordPress knows what content is relevant for the electric current folio based on the kind of page that'southward being visited. So for an archive folio information technology will know what kind of annal folio it is (a category annal, for example), and for a single mail or page it volition know which post or page is existence output. It volition use the right template file from the theme (using the theme hierarchy) to output the relevant loop for the electric current content type.

Let's take a look at this in action.

Single Posts and Pages

The loop for single posts and pages will only exist run once, because simply the content for one postal service or folio needs to exist shown. WordPress knows this because it knows what kind of page it'due south showing in your site and will only fetch the electric current post or page.

The loop for a single post will look something like this:

This is a simplified version of the loop. In nearly themes it will also include more metadata, a list of categories, and comments. Only it shows yous how the core content of the mail service or page is output.

Everything is enclosed in an commodity chemical element with an ID of the post ID and classes that are set using the post_class() template tag. There's then an h1 element with the post championship and a section for the content using the the_content() template tag.

All this is done automatically by accessing the database, meaning in that location'southward only one file for all your single posts—the template file.

A loop for a page volition look very similar and is less likely to have metadata and comments, but that will vary according to your theme.

Archive Pages

Archive pages besides utilize the loop, merely instead of outputting just one mail service, they will fetch multiple posts and display them all. Then, for example, a category archive volition output all posts in that category.

Once again, WordPress knows to exercise this based on the page that's being displayed. This is where the while() part of the loop is more than obvious because WordPress will keep going through the loop once more and again while there are posts to display.

Here's an example loop for a category archive:

There are a few key differences here compared to the single postal service or page:

  • The title is inside an h3 tag, non h2. This is considering the title of the archive folio volition be in an h2 tag.
  • The title is inside a link to the post using the_permalink(). This means that a visitor can click through to the individual post from the archive folio.
  • The featured prototype is being output as part of the archive page design. This is optional but will encourage more clicks through to the post. It's also enclosed in a link to the post.
  • An excerpt of the post is output, instead of the entire content. In some blogs, the entire content is output on annal pages, but if you just use an excerpt, information technology volition mean less scrolling for people to come across all your posts in that archive.

There are differences, merely as you can see, athenaeum are using the loop just like single pages and posts—and they're using information technology to access the database, fetch the content saved in the wp_posts table, and output that.

The Home Page

The way the home page is displayed will depend on how you lot've set it up. Your domicile page tin can be either a list of your most contempo posts or a static page. You tin configure this in the Settings bill of fare in the WordPress admin.

If your home page is a static page, then information technology volition usually use the same template file as the other static pages in your site and the aforementioned version of the loop. This is unless your theme has a specific template file for the dwelling house folio. Sometimes a template file like this will exist used to fetch the contents of the page and output extra content such every bit a slider which is just on the domicile folio. Either way, the loop will be like the loop we saw in a higher place for unmarried pages.

If your home page is an archive of your latest posts, information technology won't apply the archive.php template file (annoyingly), just instead will use a template file specifically for the home page or, if there isn't one, information technology will use the alphabetize.php file, which is the catch-all template file for whatever pages that don't have a more specific template file.

It'll work through the loop again and once again, fetching and outputting probably the most recent posts in your site and showing either the excerpt or the full content. This depends on the code in your loop.

So whichever way your domicile folio is set, it'll still exist using the loop to admission the database and fetch either the single static folio or the list of recent posts.

Summary

WordPress's power comes from the fact that it's a content management system. This ways that to create a website, you don't accept to write whatsoever code. Instead, you create posts and pages in the WordPress admin screens, and WordPress saves those to the database and so they can be output on the relevant pages of your site so people tin can visit them.

This makes information technology much easier for you to create and manage your site and for the site to abound to include as much content as you demand. Be sure to check out our learning guide if you want to larn more WordPress evolution.

The Best WordPress Themes and Plugins on Envato Marketplace

Explore thousands of the all-time WordPress themes ever created on ThemeForest and leading WordPress plugins on CodeCanyon. Purchase these loftier-quality WordPress themes and plugins and improve your website experience for you lot and your visitors.

WordPress themes on ThemeForest WordPress themes on ThemeForest WordPress themes on ThemeForest

Hither are a few of the best-selling and up-and-coming WordPress themes and plugins available for 2020.

Did you lot find this post useful?

Where Are Pages 7 Templates Stored,

Source: https://webdesign.tutsplus.com/articles/where-are-pages-stored-the-wordpress-database--cms-35169

Posted by: rosstooll1958.blogspot.com

0 Response to "Where Are Pages 7 Templates Stored"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel