Once you’ve got the file ( cool-page-template.php, of whatever you prefer), you should start it like this: Īnd you’re basically done. As we touched on above, WordPress’s template hierarchy thinks it owns a file named with that pattern.) (Which means: do not use a name like page-whatever.php. It doesn’t really matter, as long as you don’t actually use a name that’s part of the template hierarchy, you’re golden. What you’ll do is, add to your theme (and it really should be a child theme unless there’s a very strong constraint making that impossible for you) a file with a name like my-template.php or really-cool-awesome.php. So it’s time to get to the process for creating a WordPress custom page template. And that we’ll make use of them on actual pages of our WordPress site by selecting them from a “Template” dropdown menu on the right-bar of the relevant piece of content. OK, so we know that custom page templates will supercede the WordPress template hierarchy. With the numeric or slug-based page-*.php structure, you’re forced to make your theme know about the specific way your WordPress database data is right now. (So if you reuse the theme on a different WordPress site, for example, that file is useless.) How Do I Make a WordPress Custom Page Template? For that reason, I’d recommend it in just about every situation when you’re unsure which to go with. If you’re wondering why you’d use this method as opposed to the numeric or slug one - in either case you’re creating a custom file in your theme, after all - the reason is that using custom templates gives you more flexibility and independence between your theme and your site’s database and content. (The difference between the Custom template, and one with this page-$id or page-$slug structure is really only in interaction and interface.) If neither of those is found, WordPress will fall back to page.php, if it exists, and if not we’d end up at the ultimate fallback, index.php. If not, then the WordPress template hierarchy will look for a somewhat different way that someone might have tried to style a specific page - with a page-123.php or page-custom-template-utilizer.php file. To restate that, if a custom page template is selected, that “template” file will be used. If a Custom Page Template was selected in the dropdown we showed above, that “template” file will be used. This “selected template” essentially replaces the whole selection process of the template hierarchy. The specific thing we’re meaning today, though, sits outside of the template hierarchy. (Here’s our quick intro to it.) Almost everything else is a detail you can work out once you’ve understood the basic dynamic of the template hierarchy. I’ve written before, and I’ll likely do so again, about how the template - there’s that word again - hierarchy is really the key concept you need to understand to build or modify a WordPress theme. How Does This Fit Into the Template Hierarchy? But this selectable dropdown of named page templates is what we’re talking about here today. If you see this dropdown, it’s because your theme provides some of these “custom page templates.” They’re actually files in your currently active theme’s folder (or its parent), and have a single distinguishing feature we’ll come to later. This selection box is illustrated on the right (it’s also on the right side of your “page editing” screen). And while editing your page, you notice the “Page Attributes” box, And within that, you might (dependent on if your theme already has these templates) see this “Template” dropdown. For example, you’re editing the Page content type in WordPress (although, as we’ll see later, it can now include other WordPress content types). So what do I mean by “custom page template”? I mean what is shown at right. The first thing I *don’t* mean when saying “WordPress custom page template” is “a WordPress theme.” (Many people new to WordPress say “templates” when they mean “a WordPress theme.”) As I hinted at above, there are a lot of things with the vague notion of “page” and “template” in the WordPress world that aren’t what we’re talking about here. There’s a huge terminology problem with this topic.
0 Comments
Leave a Reply. |