-
Notifications
You must be signed in to change notification settings - Fork 1
Builder
The builder function is a very simple way of creating loops within a Wordpress theme, and display them using a wide range of layouts.
- Allow layout files (molecules and organisms to be re-used, vastly reducing code duplication and increasing efficiency
- Removes any reliance on having to code the loop itself
- Allow flexibility of using custom loops as well as the default Wordpress loop, if you need to create something special
##Usage Examples
In its most basic form, use
build();
This will display a simple ul list.
It is possible to use any file contained with the layouts/organisms folder within the builder function. So for example, if you would like to display a snippets (one of the layouts available) you could use:
build('snippets');
Note that the builder function will automatically create a WordPress loop for you too – all you need is the buolder(); function and you're all set.
If you need to pass a custom argument to the layout, it can be passed using the second parameter accepted by the build function:
build('ordered-list', array('classes' => 'a-new-class some-selector'));
The build function has a third parameter which can be used as the arguments for a WP_Query object. If this argument is not provided, the standard Wordpress loop will be used.
$wp_query_args = array(
'post_type' => 'post',
'posts_per_page' => 3,
'orderby' => 'post_date',
'order' => 'ASC'
);
build('snippets', array('classes' => 'a-new-class some-selector'), $wp_query_args);
Below is the full list of parameters accepted by the builder function. Note that each layout will only use some of these parameters, and in some cases the parameters will have more than one purpose.
<?php $args = array(
'classes' => '',
'size' => 'small-4,
'has_image' => true,
'has_caption' => true,
'has_title' => true,
'has_summary' => true,
'has_readmore' => true,
'has_date' => true
); ?>
One or more custom classes - e.g. .primary, .rounded
Typically used to represent Foundation grid classes, e.g. small-4 medium-2
Controls whether a layout will display an image, typically a featured image.
Control whether a layout will display a caption, typically a container div including a title, date, summary and that sort of thing.
Control whether a layout will display a title, typically a h2 or similar
Control whether a layout will display a summary or excerpt (used by the snippet layout, for example)
Control whether a layout will display a 'Read More' permalink
Control whether a layout will display a date – used typically by snippets and blog layouts.