Papi Project Adds a Page Type API to WordPress

photo credit: zenobia_joy - cc
photo credit: zenobia_joycc

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.

add-new-page-type-view

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.

start-page-example-page

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.


LIKE THIS

10

10 responses to “Papi Project Adds a Page Type API to WordPress”

  1. 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.

  2. I had a play around with this just now. Some observations:

    (1) This is not n00b friendly. If you aren’t happy burying your head in code, run away now.
    (2) The basic concept here is awesome. This can give a vastly simplified admin interface for handing things which can make for one hell of a messy UI for otherwise. I like it a lot.
    (3) Clean code. This makes me happy.
    (4) I can’t figure out how to make it load the correct template. Either documentation is missing, the plugin is broken, or I’m too dumb to figure it out. I didn’t put a lot of effort into working it out since I was just taking it for a spin to see how it works, but it definitely didn’t seem intuitive to me how it worked.
    (5) The CMB stuff still seems out of place. There are already very good plugins for WordPress which handle this sort of thing. I’m not see any reason to bake that functionality in here.
    (6) We need more plugins like this. I see too many custom sites which end up using a metric crap-ton of custom post-types, which results in a horridly complex interface and creates some weird URL setups, whereas a basic page is often all that is necessary. The only reason people often use custom post-types is because they need/want a way to differentiate them within the admin panel UI; this plugin works around this problem quite nicely.

    • Thanks for the feedback. Regarding the CMB I wanted a way to do this with just code and not via the admin ui that a lot of plugins does. I build Papi for me and my coworkers and released it as open source. So the CMB stuff will not be removed and Papi won’t be a programmatic interface against ACF or something other plugin.

      The idea for the plugin was to stop using CPT in a way that I think is wrong and the url as you say can’t be so good with CPT as you can’t place CPT below regular pages. In one project we solve this with a shortcut that a page fetched all post data from a CPT but this ins’t so great.

      But I hope that the idea around Papi can be a new way to think about pages in WordPress in bigger sites. It’s free to use as you wish or fork to build your own great plugin.

  3. I like this idea, a lot. I think it is necessary having something like this. I always say that CPT are okay if we need more than one item with a custom structure. When a CPT is set, you get the chance of adding as many items as you need. So if this is what you need, it is more than fine to use CPT.

    However, when you need a specific page with a custom structure, CPT is no longer a valid solution, since you would still have the chance of adding many items and it would break the original requeriment.

    I haven’t had the chance of taking a look at Papi, but I believe something like this is a necessary approach.

    Thanks a lot for you hard work and for contributing this big!

  4. I’ve been using Papi for some month and in a couple of projects now and I’m impressed. Give it some time and you will miss the Page Type concept if you´r not using Papi in WordPress projects.
    Thanks, Fredrik! Your plugin is fantastic!

    Don’t forget to take a look at the testing process that comes with the source code to Papi!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Newsletter

Subscribe Via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Discover more from WP Tavern

Subscribe now to keep reading and get access to the full archive.

Continue reading