Skip to content
Chris Reynolds edited this page Oct 23, 2015 · 28 revisions

Table of Contents


####wds_page_builder_load_part( $part = '' )

Load a specific template part by its slug. Functions similar to get_template_part but checks whether they exist and identifies parts by their slug. Used by wds_page_builder_load_parts.

$part The part slug

Example

<?php wds_page_builder_load_part( 'comments' ); ?>

This will load a template part named comments.php.

####get_page_builder_parts() Since 1.5

Gets an array of page builder parts.

Note, this function ONLY returns values AFTER the parts have been loaded, so hook into wds_page_builder_after_load_parts or later for this to be populated.

Example

function get_template_parts() {
     $parts = get_page_builder_parts()
     /* ...do something with $parts... */
}
add_action( 'wds_page_builder_after_load_parts', 'get_template_parts' );

####wds_register_page_builder_options( $args = array() ) Since 1.5

Function to programmatically set certain Page Builder options.

$args An array of arguments matching Page Builder settings in the options table.

  • 'parts_dir' The directory that template parts are saved in
  • 'parts_prefix' The template part prefix being used
  • 'use_wrap' 'on' to use the container wrap, empty string to omit.
  • 'container' A valid HTML container type.
  • 'container_class' The container class
  • 'post_types' A post type name as a string or array of post types
  • 'hide_options' True to hide options that have been set, disabled to display them as uneditable fields. hide_options is true by default.

Example

function this_register_options() {
	wds_register_page_builder_options( array(
		'hide_options'    => 'disabled', // this is required to actually hide the options from the options page
		'parts_dir'       => 'pagebuilder',
		'parts_prefix'    => 'thepart',
		'use_wrap'        => 'on', // on is TRUE
		'container'       => 'div',
		'container_class' => 'template-part wrap',
		'post_types'      => array( 'post', 'page', 'car' ),
	) );
}
add_action( 'init', 'this_register_options' );

####wds_page_builder_theme_support( $args = array() ) Since 1.5

Helper function to add Page Builder theme support.

Because theme features are all hard-coded, we can't pass arguments directly to add_theme_supports (at least, not that I'm aware of...). This helper function MUST be used in combination with add_theme_support( 'wds-simple-page-builder' ) in order to pass the correct values to the Page Builder options.

$args An array of arguments matching Page Builder settings in the options table.

  • 'parts_dir' The directory that template parts are saved in
  • 'parts_prefix' The template part prefix being used
  • 'use_wrap' 'on' to use the container wrap, empty string to omit.
  • 'container' A valid HTML container type.
  • 'container_class' The container class
  • 'post_types' A post type name as a string or array of post types
  • 'hide_options' True to hide options that have been set, disabled to display them as uneditable fields. hide_options is true by default.

Example

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' );

####register_page_builder_area( $name = '', $templates = array() ) Since 1.6

Function to register a new page builder "area"

$name The area name
$templates You can define the templates that go in this area the same way you would with register_page_builder_layout

Examples

/**
 * registers a Page Builder area named 'hero' with templates 
 * configured on the singular edit page
 */
register_page_builder_area( 'hero' );
/**
 * registers a Page Builder area named 'hero-archive'. Templates 
 * do not display on any singular edit page, area is uneditable 
 * and only uses the parts that have been registered
 */
register_page_builder_area( 'hero-archive', array(
     'other-articles',
     'instagram',
     'join-now'
) );

####wds_page_builder_area( $area = '', $post_id = 0 ) Since 1.6

The function to load a specific page builder "area"

$area Which area to load. If no page builder area is found, will look for a saved layout with the same name.
$post_id Optional. The post id. If no post ID is passed, and we're on a singular page, get_the_ID is used to try to get the post ID for the currently queried post.

Example

<?php wds_page_builder_area( 'test-layout' ); ?>

####get_page_builder_areas() Since 1.6

Gets an array of all the page builder areas.
Returns false if there are no areas or an array of layouts if there's more than one.

Used by get_page_builder_area.

####get_page_builder_area( $area = '', $post_id = 0 ) Since 1.6

Function that can be used to return a specific page builder area.

$area The area by slug/name.
$post_id Optional. The post id. If none is passed, we will try to get one if it's necessary (e.g. we're on a singular page).

wds_page_builder_get_this_part_data( $meta_key )

Grabs the value of the current template part's meta key. Since 1.6

$meta_key Required. The meta key to find the value of.

Example

$slides = wds_page_builder_get_this_part_data( 'coverflow_slide' );

if ( $slides ) {
     foreach ( $slides as $slide ) {
          // Do stuff.
     }
}

wds_page_builder_get_part_data( $part, $meta_key, $post_id = 0 )

Since 1.6

Grabs the value of specific meta keys for specific template parts.

$part The template part slug or index/slug array.
$meta_key The meta to find the value of.
$post_id The Post ID to retrieve the data for (optional).

Example

 <article id="post-<?php the_ID(); ?>" <?php post_class( 'hero-grid-card trending-item' ); ?>  style="background: url('<?php echo esc_url( wds_page_builder_get_part_data( 'hero-cards', 'hero_custom_content_image' ) ); ?>') no-repeat center center; background-size: cover;">
 	<div class="content-area">
 		<h2 class="title"><?php echo esc_html( wds_page_builder_get_part_data( 'hero-cards', 'hero_custom_content_title' ) ); ?></h2>
 		<a class="read-more alt" href="<?php echo esc_url( wds_page_builder_get_part_data( 'hero-cards', 'hero_custom_content_url' ) ); ?>"><?php echo esc_html( wds_page_builder_get_part_data( 'hero-cards', 'hero_custom_content_button_text' ) ); ?></a>
  	</div><!-- .content-area -->
 </article><!-- #post-## -->

wds_page_builder_get_option( $key = '', $default = false )

Since 0.1

Wrapper function around WDS_Page_Builder_Options::get()

$key Options array key.
$default A default value for the option.

wds_page_builder_container()

Helper function to return the main page builder container element

wds_page_builder_container_class()

Helper function to return the main page builder container class

wds_page_builder_get_parts()

Get a list of the template parts in the current theme, return them in an array.

get_saved_page_builder_layout_by_slug( $layout_name = '' )

Since 1.6

Return a saved layout object by its slug.
Note: This only works with layouts created after 1.6.

$layout_name The post slug of the pagebuilder layout.

get_saved_page_builder_layout( $area = '', $post_type = '' )

Since 1.6

Return the last saved layout for a given area and post type.

$area The pagebuilder area to query by.
$post_type The post type of the post displaying the area.

spb_register_template_stack( $location_callback = '', $priority = 10 )

Since 1.6

Register a template parts folder to the Page Builder template stack.

$location_callback Callback function that registers the folder in the template stack. $priority Priority for registering the folder.

See Page Builder Template Stack

spb_get_template_stack()

Since 1.6

Get all the template files in the page builder template stack.

See Page Builder Template Stack

has_page_builder_part( $template = null )

Since 1.6

Check if a page has a specific page builder part.

$template The template we're looking for.

is_page_builder_page()

Since 1.6

Checks if this is a page that has page builder templates assigned to it.

get_page_builder_part_files()

Since 1.6

Get all the page builder part files across all Pagebuilder-based plugins/themes.

Clone this wiki locally