First, let&apos;s look at why many of us build on WordPress.
How many of you have heard some version of this question?It&apos;s this question that led me to this topic, to help spread the word that WordPress is so much more than a blogging platform.
First, let&apos;s look at why many of us build on WordPress.
I would go so far as to say… You may think you know WordPress, but I would bet some of you are actually stuck in a rut of doing things a certain way because it seems to work. That&apos;s fine, but are you sure your way makes sense to the final content creator? Examining your process from a content-first perspective leads to cleaner themes and happier users.
A thorough understanding of how WordPress retrieves and relates content leads to:
But wait… how do you get started developing in a content-driven way?This may depend on if you&apos;re a single-person shop or within an agency of some sort. Personally, I&apos;m in the marketing department of a large corporation, but I also develop custom WordPress builds for freelance clients. No matter your situation, a content-first approach begins with asking:
In this example, the first three are native behaviors, but the dynamically-related sidebar content needs more consideration.
--- Learning to consider content relationships may lead you to think of even a &quot;simple&quot; marketing site in a more app-like way.Another way to consider relationships is by asking:
Let&apos;s look at developing the dynamic sidebar for our blog post example. So - this means that choosing the category for a post should be very purposeful, possibly even limited to a few strategic options.Or - maybe categories are actually types of portfolio work, so the related widget will pull in other logo posts.Or - maybe categories are used to identify courses for a recipe focused website, so the widget will show related main dishes.
Categories can be used in those previous examples IF the site is very focused on those types of subjects. But let&apos;s look at a larger example.
... and each of those comes with it&apos;s own set of questions to narrow down the type of content to be entered for each. To figure out how to handle each of these, we need to find out...
To determine our content creation structure, it&apos;s helpful to learn how WordPress displays and relates different content.
--- Here&apos;s where content-first approach takes hold. Even seasoned developers have trouble with or completely miss the concept of how to define home page content. It took me a few years to stumble upon the correct information. The confusion stems from...
I think this refresher may help more than the n00bs in the crowd. Public confession: I&apos;ve only done this setup correctly for sites I&apos;ve built in the past 6 months.
Now that we&apos;ve looked at how WordPress uses index, home, and front page templates, you can see why we&apos;ve started there with our content-first development. --click-- It&apos;s important to consider the site&apos;s purpose before you even go so far as to create the structure for the front page. Here&apos;s a few common scenarios that dictate the front page:
...I mention this because it&apos;s how I did it until I took the time to finally get these three templates straightened out in my head! If you&apos;ve been doing it this way too, perhaps you might benefit from knowing that defining the posts page means the query is all ready for you, including the paged variable. Just write a normal loop and include posts navigation and everything will work smoothly!
Let&apos;s continue on and look at… Ok, this one is pretty basic. In fact, it&apos;s probably the first thing you learned when you signed up for a WordPress.com account and upgraded from your Blogger account. But let&apos;s review:
An additional layer of data you can include by default on either posts or pages is custom meta. In terms of content-driven development, this allows you to expand on the content entry ability default posts and pages in a comfortable but very useful way.
If the site you&apos;re building needs a blog, an About page, and a Contact page, sticking with just Posts and Pages is all you need to worry about.But if you&apos;ve spent time developing custom solutions, you know that Posts and Pages can be pretty limiting. For any advanced functionality, you may be creating numerous custom page templates, and likely struggling with relating content beyond a parent/child relationship for pages and categories or tags for posts.Custom meta data can get you part of the way if you choose to use that to alter a query. However, custom meta can also lure you to the dark side of customization: offering too many options that aren&apos;t needed for every single entry. --CLICK--Custom Post Types, or CPTs, allow you to define a wholly unique type of content. Today we&apos;ll look at CPTs more theoretically rather than discuss every option available in creating them. Custom Post Types, or CPTs, allow you to define a wholly unique type of content. Today we&apos;ll look at CPTs more theoretically rather than discuss every option available in creating them.
I am of the school of thought that any functionality that creates new content belongs in a plugin so that site owners don&apos;t lose access should they switch themes. You could argue that CPTs belong in themes because you may need to create templates to accommodate them. We&apos;re not going to spend time going over all the pros and cons today, but it&apos;s something to consider as you create a site that best fits your client&apos;s needs.
Back to our earlier example, one of the requirements for our marketing site was a resources section with the following types of content:
Now that we know what content elements we&apos;d like for each view, it&apos;s time to consider what UI elements we&apos;ll need for the user to enter that content. Based on what we&apos;ve mapped out, and what we now know about various content types in WordPress, we&apos;ll need...
We also know we&apos;ll want to...
Our newsletter resource type is in need of a way to link posts belonging to the same issue, such as &quot;Spring 2014&quot;. Custom taxonomies are how we can achieve this because of:
Now that we know what both of these are, a quick rule of thumb for choosing one over the other:
Ok, we&apos;ve settled how we&apos;re entering content, so now let&apos;s look at creating the view for the theme. --CLICK-- When we reviewed pages, we saw that there were multiple options in the template hierarchy for pages, and we need to choose one to customize our resources page. ---- For our purposes, we&apos;ll chose to create a custom template template-resources.php because the risk of the slug changing is greater than if the template was applied to multiple pages. If you have fewer content editors, and perhaps have already had an SEO review validating your slug choice, you may decide to go with the slug option.
Thanks to our careful content-driven structure, we can create the three loops we need on this page with ease!Our wireframe included showing up to 10 case studies and white papers in their own section, plus a newsletter section with all entries from the latest issue.
One semi-tricky thing about Custom Post Types is they will use single.php as a default template. For our single resource views, we want a little extra markup to display the download document button, plus include a special sidebar. --CLICK--I&apos;d like to introduce a pattern used by the excellent starter theme _s. It keeps things simple by only having single.php but modifying the default loop as follows:
See the power in that? Now we can simply customize the guts of each post based on it&apos;s type.
For our purposes, the case study and white paper pages content will be the same, so we&apos;ll take this our single.php loop one step further:--- Then, we can include the document download button just on content-document.php, and include the name of the issue on content-newsletter.php.
We can employ a similar conditional to alter which sidebar gets included back on the single.php template: