-
Notifications
You must be signed in to change notification settings - Fork 25
Handy Functions
Table of Contents
- wds_page_builder_load_part
- get_page_builder_parts
- wds_register_page_builder_options
- wds_page_builder_theme_support
- register_page_builder_area
- wds_page_builder_area
- get_page_builder_areas
- get_page_builder_area
####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
istrue
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
istrue
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).
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.
}
}
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!