-
Notifications
You must be signed in to change notification settings - Fork 25
Handy Functions
Table of Contents
- wds_page_builder_load_parts
- wds_page_builder_load_part
- page_builder_class
- get_page_builder_class
- get_page_builder_parts
- wds_page_builder_wrap
- 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
Load an array of template parts (by slug). If a string is passed, it can be used as a wrapper for the wds_page_builder_load_parts action.
$parts (Optional) A specific layout or an array of parts to display
Examples
<?php wds_page_builder_load_parts( 'test-layout-2' ); ?>
This will do the same thing as do_action( 'wds_page_builder_load_parts', 'test-layout-2' )
.
<?php wds_page_builder_load_parts( array(
'instagram',
'author-bio',
'related-posts',
) ); ?>
This will explicitly load the three named template parts by their slug.
Source: inc/template-tags.php
####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 part-comments.php
.
Source: inc/template-tags.php
####page_builder_class( $class = '' )
Display the classes for the template part wrapper.
$class One or more classes to add to the class list
Example
<div <?php page_builder_class( 'my-new-class' ); ?>>
<!-- do stuff -->
</div>
Since 1.5
Source: inc/template-tags.php
####get_page_builder_class( $class = '' )
Retrieve the class names for the template part as an array. Use page_builder_class
if you want the classes to output in a div (or not as an array).
Based on post_class, but we're not getting as much information as post_class. We just want to return a generic class, the current template part slug, and any custom class names that were passed to the function.
$class One or more classes to add to the class list
Example
echo '<div class="' . join( ' ', get_page_builder_class( 'my-class' ) ) . '">';
Since 1.5
Source: inc/template-tags.php
####get_page_builder_parts()
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' );
Since 1.5
Source: inc/template-tags.php
####wds_page_builder_wrap( $container = '', $class = '', $layout = '' )
Helper function to display page builder with a full wrap.
Note, this should be used only if the option to use a wrapper is disabled, otherwise, you'll get the page builder contents twice.
$container Optional. Unique container html element or use the default
$class Optional. Unique class to pass to the wrapper -- this is the only way to change the container classes without a filter.
$layout Optional. The specific layout name to load, or the default.
Since 1.5
Source: inc/template-tags.php
####wds_register_page_builder_options( $args = array() )
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' );
Since 1.5
Source: inc/template-tags.php
####wds_page_builder_theme_support( $args = array() )
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' );
Since 1.5
Source: inc/template-tags.php
####register_page_builder_area( $name = '', $templates = array() )
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'
) );
Since 1.6
Source: inc/template-tags.php
####wds_page_builder_area( $area = '', $post_id = 0 )
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' ); ?>
Since 1.6
Source: inc/template-tags.php
####get_page_builder_areas()
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
.
Since 1.6
Source: inc/template-tags.php
####get_page_builder_area( $area = '', $post_id = 0 )
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).
Since 1.6
Source: inc/template-tags.php
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!