-
Notifications
You must be signed in to change notification settings - Fork 24
Using the Page Builder
Since this is primarily a developer-centric tool with a customer-facing component, the scope of this document will, out of necessity, bounce between both audiences. As such, I've broken the steps for each into different sections.
Getting started with the Simple Page Builder for users is pretty simple.
- Set up the options.
- (Optional) Set the default layout or any custom layouts for specific post types.
- Add post- or page-specific layouts on those post/page's Edit screens.
- Profit!
If you're building a theme for yourself or a client, there are a few things you need to implement the Page Builder.
-
Set up the options or hard code them with
wds_register_page_builder_options(Recommended). -
Add the Page Builder areas with
wds_page_builder_areainto your template files. This is required. This is the only thing telling WordPress to load the template parts with Page Builder. If no areas have been registered, Page Builder is equipped with a single, default area that's used when no specific area name has been passed. See Page Builder Areas for information about registering and using Areas. - Build your template parts. Make sure you're building the ones you want available to use by Page Builder in the directory and with the prefix defined in the options.
Adding the Page Builder action is really simple.
<?php wds_page_builder_area(); ?>
That code will kick the Page Builder off and load the template parts that were defined in the individual post (if you're editing a singular theme template file like single.php or page.php), the default layout for that post type (if defined in the options page) or the default layout (if it exists, if that post type is set to always use the page builder and nothing else was set). When no parameter is passed to wds_page_builder_area, the built-in Page Builder default area is used.
You can also call specific layouts in your theme files (using get_saved_page_builder_layout or defined areas by passing a parameter to wds_page_builder_area.
<?php wds_page_builder_area( 'hero' ); ?>So...where do I put the do_action?
This is an interesting question because it depends a lot on what your template parts are doing and what type of content they will be rendering, specifically if they expect to be in the Loop (using template tags like the_title and the_permalink that only work after the_post or setup_postdata has run) or if they are more generic (like pulling in a Twitter feed).
My recommendation is to assume all template parts are being used outside the Loop to avoid any potential in-the-Loop/out-of-the-Loop problems. If everything is built assuming it's used outside the Loop, you can still use get_queried_object on whatever pages you're adding the template parts to to get the WP_Query (for archive pages) or WP_Post (for singular pages) object or add your own WP_Query to your template part without clashing with the current query.
There are some times where this might not be possible. For example, if you are using template parts to load components that must be used inside the Loop (like comments). For those situations, you can call the do_action twice in your template -- once inside the Loop (using a specific, named layout), and once outside the Loop (using the default settings for that singular post or post type). An example single.php that uses the do_action inside and outside the Loop is available here.
Still missing something? Let us know if you think this wiki is missing some information or could use some more details! Open an issue in the issue tracker with the information you're looking for and we'll make sure that information gets added!