Creating Unique and Customizeable Layouts with Simple Page Builder

Swipe to start

Chris Reynolds

I’m a developer for WebDevStudios
I’m an author for Pluralsight
I make lots of plugins
I also have a theme on WordPress.org
Lots of my stuff is on Github, though
I tweet a fair amount
Go Real Salt Lake!

Who is this guy?

In the beginning…

...it was a dark, dark time...

In order to do something like this...

...you had to do something like this

…or this

…or this

WTF is all this stuff?

There must be a better way!

...widgetception...

banner-1544x500

…enter Simple Page Builder

https://github.com/WebDevStudios/WDS-Simple-Page-Builder

How it works

Template parts

 

NPS__CLP__Git_browser

How it works

Template parts

 

Add_New_Page_‹_NPS__Common_Learning_Portal_—_WordPress

How it works

A user adds as many parts as they want

 

template-parts-demo

But what if you’re not on a Page?

What if you’re on a Post or a Custom Post Type?

But what if you’re not on a Page?

Select what post types you want to support

 
page-builder-main-options

https://github.com/WebDevStudios/WDS-Simple-Page-Builder/wiki/Page-Builder-Options

But what if you’re not on a Page?

Set a global default

 
global-default

https://github.com/WebDevStudios/WDS-Simple-Page-Builder/wiki/Page-Builder-Options#global-template-parts

But what if you’re not on a Page?

Create custom fallback layouts for all posts of a type or name them and call them directly in the code

saved-layouts

https://github.com/WebDevStudios/WDS-Simple-Page-Builder/wiki/Setting-Saved-Layouts

This makes the magic happen

 

<?php wds_page_builder_load_parts(); ?>

Use this to load a specific, saved layout

 

<?php wds_page_builder_load_parts( 'my-layout-name' ); ?>

Set up options for wrapping each template part in an HTML container

 
Page_Builder_Options_‹_NPS__Common_Learning_Portal_—_WordPress

Pre-load options and hide them from the Options page

function this_register_options() {
    wds_register_page_builder_options( array(
        'hide_options'    => true,    // this hides the options from the options 
                                      // page, use 'disabled' to display them as 
                                      // disabled input fields
        'parts_dir'       => 'parts', // where the template parts are stored
        'parts_prefix'    => 'part',  // the template part prefix, like 
                                      // part-my-template-part.php
        'use_wrap'        => 'on',    // on is TRUE
        'container'       => 'div',   // the container type, can be any valid 
                                      // HTML5 element
        'container_class' => 'template-part wrap',           // default classes 
                                                             // for the wrapper
        'post_types'      => array( 'post', 'page', 'car' ), // allowed post 
                                                             // types
    ) );
}
add_action( 'init', 'this_register_options' );

Add theme support for Page Builder

function wds_setup_theme() {
    add_theme_support( 'wds-simple-page-builder' );
    wds_page_builder_theme_support( array(
        'hide_options'    => 'disabled',          // set to true to hide them 
                                                  // completely
        'parts_dir'       => 'pagebuilder',       // directory the template parts
                                                  // are saved in
        'parts_prefix'    => 'part',              // the template part prefix, 
                                                  // e.g. part-template.php
        'use_wrap'        => 'on',                // Whether to use a wrapper 
                                                  // container. 'on' is TRUE
        'container'       => 'section',           // HTML container for Page 
                                                  // Builder template parts
        'container_class' => 'pagebuilder-part',  // can use multiple classes, 
                                                  // separated by a space
        'post_types'      => array( 'page', ),    // add any other supported post 
                                                  // types here
    ) );
}
add_action( 'after_setup_theme', 'wds_setup_theme' );

Add theme support for Page Builder

 

if ( current_theme_supports( 'wds-simple-page-builder' ) ) {

     // do stuff

}

Ever wanted to conditionally load a javascript file on a certain page, but only if that page was using a particular feature or component?

Page Builder makes this easy-peasy

 

    add_action( 'wds_page_builder_after_load_parts', 'load_flipster' );

    /**
     * Function to conditionally enqueue the flipster js based on whether the 
     * template part is in use on the page.
     * @since  0.1.0
     * @return void
     */
    function load_flipster() {
        $parts = get_page_builder_parts();
        // only load flipster on pages that use the coverflow part
        if ( in_array( 'coverflow', $parts ) ) {
            wp_enqueue_script( 'jquery-flipster', $this->url . '/assets/bower/
            jquery-flipster/dist/jquery.flipster.min.js', array( 'jquery' ), 
            '20150723', true );
        }
    }

Page Builder Areas

They’re kind of like widget areas

Restrict template parts to specific areas

 

/**
 * Part Name: My Template Part Name
 * Description: A cool description about my part
 * Areas: before_content, after_content, content, hero
 */

pagebuilder-post-data

Coming Soon!

Add external folders for template parts (plugin, parent/child theme support)

Docs!

https://github.com/WebDevStudios/WDS-Simple-Page-Builder/wiki

http://webdevstudios.com/2015/07/07/add-unique-layouts-content-page-builder/

 

Try it out!

https://wordpress.org/plugins/wds-simple-page-builder/

https://github.com/WebDevStudios/WDS-Simple-Page-Builder/

 

left-shark

Questions???

https://chrisreynolds.io/wcslc2015

This presentation was made using story|FTW. Check it out on WordPress.org:
https://wordpress.org/plugins/storyftw/

Let's go!

  • Creating Unique and Customizeable Layouts with Simple Page Builder
  • Who is this Chris Reynolds guy?
  • In the beginning
  • In order to do this
  • You had to do this
  • Or this
  • Or this
  • WTF?
  • There must be a better way
  • The Maintainn project
  • Content editors shouldn’t need to know html
  • Widgetception
  • Enter Page Builder
  • How it works — Template Parts
  • How it Works — Template Parts backend
  • How It Works add as many template parts as you want
  • But what if you’re not on a Page
  • We’ve got you covered
  • Set global defaults or per-post-type defaults
  • Or custom layouts that are named or set for the post type
  • Let’s see some code
  • Load a specific layout
  • Layout options
  • Pre-load options and hide them from the user
  • Adding theme support
  • Check theme supported features
  • Load javascript files conditionally
  • Load javascript files conditionally code
  • Page Builder Areas are like Widget Areas
  • Page Builder Areas
  • New Feature: restrict template parts to specific areas
  • New feature: passing data to template parts
  • Features coming soon
  • Documentation!
  • Questions
Share Tweet
Creating Unique and Customizeable Layouts with Simple Page Builder