
The Pages feature, although generated dynamically in WordPress, was designed for use with static, evergreen content. Pages have always been somewhat simpler than posts, which received a major boost to flexibility when custom post types came on the scene in version 3.0.
Fredrik Forsmo, a systems developer in Stockholm, Sweden, wanted to do more with pages and decided that WordPress needs a Page Type API. He created Papi, an open source project that offers a less traditional approach to working with fields and page types.
“Papi was started because creating page types didn’t exists in a good way,” Forsmo said. “ACF and other plugins only support custom fields on different post types. This is not a good way to create page types. Additionally, the URL structure isn’t ideal with custom post types.”
Inspired by the lack of adequate solutions to address this need, Forsmo spent a year developing Papi in his spare time. The idea for the project is based on EPiServer’s Page Type Builder, which offers a more object oriented method of building pages. Papi brings this same approach to WordPress.
Essentially, it allows you to create page types using an existing post type or using custom post types. It doesn’t have an admin user interface for adding all the fields. “Papi uses classes in PHP, where one class represents one page type and in your class you add all fields you need,” Forsmo explained.
After running it in production, he discovered that it’s easy to work with when it’s necessary to add new fields. Using Papi’s “page” post type, you can create different page types with different fields on the same post type, while maintaining a clean URL structure.
Forsmo believes that this is the way pages should work in WordPress. Although I don’t know if the idea will catch on with developers, the project seems useful for those rare scenarios where custom post types aren’t a good match.
Papi isn’t on the WordPress plugin directory but can be downloaded from GitHub. It’s also available as a Composer package. Papi currently works on WordPress 3.8+ (3.9+ if on HHVM) and PHP 5.3 and above. If you want to experiment with it, Forsmo has written documentation on how to get started, how to add page type meta boxes and options, functions available to use in your page type, and how to register a page type directory.
I like the direction this is heading.
Perhaps this would be better tackled by forcing the same page-type selector, but simply allowing users to choose from existing page templates there. Then you could use your custom meta box plugin of choice to control the meta boxes used for each template.
I’ve also seen some custom themes which have forced users to select a page template before publish a page. That way you know the user has thought about which page type they’re publishing and not just accepting the defaults.