In this post for WordPress tecchies I’ll tackle a subject that crops up a fair bit in building sites for clients – whether to use the default archive functionality or to create a static ‘Page’ and use that as the parent for single Custom Post Type (CPT) posts. There’s no right or wrong answer but each has its own pros and cons – I’ll cover them here and share the solution that works best for me in many situations. If you’ve got any suggestions for improvements or alternatives then I’d love to hear from you in the comments.
Note: This post refers to the Genesis Theme Framework, which I use on all my sites. The fundamental WP principles apply though.
What we’re trying to achieve:
For simplicity’s sake, let’s say that we have a CPT of ‘Friends’ – and there’ll be six entries: Ross, Rachel, Chandler, Joey, Monica and Phoebe. And we want a page/archive titled ‘Meet the Friends‘ that lists them all in a grid with their image and name. Each item in the grid clicks through to the individual CPT entry.
So the url for the ‘grid’ page will be mysite.com/friends and an individual entry will be mysite.com/friends/chandler
We’re building the site for a client so we need it to be easy and intuitive for them to use and update. I like to use breadcrumbs, or at least have the option to turn them on, so they need to work properly – by which I mean when you’re on a single entry the breadcrumb should look something like Home >> Meet the Friends >> Chandler whereby the Meet the Friends link should take us back to the grid page. If you’re not worried about breadcrumbs then your life is going to be much simpler as you don’t need to worry so much about setting a Page as a parent of the CPTs.
As an addition, I’m using a Dynamic Secondary menu (where the secondary menu shows the children pages within the relevant Primary menu section. So if you’re in the ‘About Us’ section the secondary menu will display the relevant menu children like ‘our staff’, ‘our history’ etc.). Regardless of whether we’ve got breadcrumbs turned on or off, I want to make use of the .menu-current
, .menu-ancestor
etc. CSS classes so we can use a different text colour in some menu items to give visitors a visual indication of where they are within the site.
The two options:
If you’re a seasoned WP developer you’ll know there’s two basic options (I’m excluding plugins like WP Views or shortcode based solutions).
- Set the Friends CPT to have an archive when registering it. Then we can use a template like
archive.php
orarchive-friends.php
and use the native WP archive functionality. - Set the Friends CPT to have no archive, and then create a static page called Meet the Friends. We can create its own template with
page-friends.php
or we could create a grid page template and assign this page to using that.
Option 1 – using a default WP archive
Pros:
- Breadcrumbs should work ‘out-of-the-box’.
- It should handle pagination fine if there’ll be a lot of ‘Friends’ created and you don’t want to fit them all on one page.
Cons:
- Archives really aren’t very intuitive for casual WP users. For me, this is one of the drawbacks of WordPress as it currently is. If the client wants to edit the title or intro text of that ‘page’ then there isn’t an ‘Edit Page’ link in the toolbar at the top, like there is for all the other pages. In my experience, the whole notion of ‘Archive Pages’ is confusing to most clients, especially ones who don’t have a blog-based site. So when using Genesis the user has to go into
Dashboard>Friends>Archive Settings
even though to them, this ‘page’ doesn’t seem very different from all the other Pages on the site. - Archives don’t natively support metaboxes. So for example if we’re using ACF for setting custom header images for pages, then there’s no ‘page’ where they can go and choose a Featured Image or other custom image. Similarly as there’s no Page Options metabox, you can’t choose which template to use.
- It’s generally more complicated to build an archive template than a page one. Whilst Genesis archives are really SEO friendly out-of-the-box, I feel like the
.article
.entry-header .entry-content .entry-footer
etc markup is a bit overkill for our intended purpose. And undoing all of that takes a bit more effort.
Option 2 – using a static page
Pros:
- This is a more intuitive solution for most casual users as they’ll be much more familiar with static Pages because they use them day in, day out. You want to edit the content of this page? there’ll be the usual ‘Edit Page’ link in the toolbar along the top.
- All the ACF custom fields and other standard metaboxes will show on the Edit Page screen – so we can set the Featured Image, Custom Header Image and whatever else.
- In my opinion, static pages are easier to template and we can set up a variety of templates so in the Edit Page screen the user can select whether they want to use a Grid template, Masonry layout etc. And those templates can be used for other lists of CPTs or child pages too.
Cons:
- Breadcrumbs won’t work properly out-of-the box because WordPress won’t know that the ‘Meet the Friends’ page is the parent of the Friends CPTs.
- Pagination won’t work either. That’s not a problem at the moment because we think there will only be 6 Friends and we want to display them all on the same page. But you never know if things might change in the future.
So which to use? It may be a remnant of WordPress’ origins as blogging platform, but it seems to me that in these cases there’s a conflict between doing it the ‘right’ way (i.e. native WP archives) vs doing it a way that is arguably better and more user-friendly (the static page as a parent of the CPT).
To me, it makes sense that post-types like blog posts and news items should use the native Archive functionality. There’s probably going to be lots of these and so pagination will be important. Plus the built-in Genesis archive HTML markup is nice and SEO-friendly.
But in our Friends case, it seems like a bit of overkill. We know we won’t want pagination, and the ease-of-use for the client is an important factor. So let’s forego the archive functionality and look at how to set this up to use a static page. It takes a bit more setup but it will ultimately be more user-friendly and will allow us to make easy use of ACF and other metaboxes that are built into regular WP pages.
A quick How-to guide to point you in the right direction
I’m not going to go into all the details of how to set this up as I’m assuming that you’ll have a working knowledge of WordPress development.
1 Set up the CPT of ‘Friends’ You can use a tool like GenerateWP or the CPTUI plugin, or hand-roll your own. From my trial and error, the most important settings to pay attention to are:
has_archive: false capability_type: page hierarchical: false rewrite: true rewrite_slug: friends rewrite_withfront: false
2 Create a normal ‘Page’ called ‘Meet the Friends’. The url can be mysite.com/friends.
3 We need a way of telling WordPress that this new page is the parent of all those CPT entries. As of WordPress v4.8 I think the best function to use is the post_parent one. I’m using this tutorial from Joe Sexton as the basis of the solution http://www.webtipblog.com/setting-wordpress-custom-post-type-parent-specific-page/ It’s an important piece in the puzzle and gets us most of the way there. The solutions presented there either hard-code the post_parent in the PHP file, or you have to set the parent for each new CPT that you add (and it’s likely that a client might forget one time). I usually make an ‘Organisation Settings’ ACF Options page for most clients, and this can be put to use. So I’ve created an ACF Post Object field which can be called friends_parent and that’s in the Organisation Settings page. Now the client can choose the Parent Page when they’re setting up the site, but they don’t need to do so for each CPT that gets created. It’s not an ideal situation as if the Parent page changes, you’d need to manually Edit>Update all the CPT posts. Perhaps there’s a better hook to use than wp_insert_post_data
but for the time being let’s go with this.
4 Here’s my code:
5 That will fix the breadcrumbs so they work properly now. Note that for some reason, the Genesis default breadcrumbs don’t display correctly but I usually use the ones supplied with Yoast SEO and those ones will work without any adjustment required. That might well be as far as you need to go.
6 I also add in the correct menu classes to my primary and dynamic secondary menu, so if the ‘Meet the Friends‘ page is a menu child of a ‘TV Shows’ primary menu item for example, then the ‘TV Shows‘ primary and ‘Meet the Friends‘ secondary menu items will be coloured slightly differently from their neighbours – so without the breadcrumbs it’s easy to see which section of the site you’re in. I won’t go into the details of how to achieve that here, but it’s based on two tutorials by Bill Erickson. See the Dynamic Secondary menu one and the Menu class one.
Viewing it in action.
This demo site of my basic charity website starter setup uses the ‘page as parent of CPT’ for the Jobs, Events and Stories page. And it uses the default WP/Genesis archive functionality for the blog and the news. It might have changed a bit depending on how far into the future from now you’re looking at it, and the breadcrumbs may be switched off – but rest assured that the Yoast SEO ones work perfectly.
Wrapping up.
The static page parent solution isn’t ideal for all situations, but for me there’s plenty ones where on balance it makes more sense than using a WP archive. I’ve built sites for lots of clients, and who have a wide range of experience and comfort with using CMSs. In my experience, the two things that are the least intuitive in WordPress and therefore generate the most requests for help are dropdown menus and archive pages. So making the user-experience a bit more uniform by sticking to static Pages will make the site more user-friendly and makes for a happier client.