Skip to content
dmseaton edited this page Nov 10, 2014 · 6 revisions

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

Basic Usage

In its most basic form, use build();

This will display a simple ul list.

Using a different layout (organism)

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.

Providing arguments

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

Using a custom loop

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

Parameters

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

classes

One or more custom classes - e.g. .primary, .rounded

size

Typically used to represent Foundation grid classes, e.g. small-4 medium-2

has_image

Controls whether a layout will display an image, typically a featured image.

has_caption

Control whether a layout will display a caption, typically a container div including a title, date, summary and that sort of thing.

has_title

Control whether a layout will display a title, typically a h2 or similar

has_summary

Control whether a layout will display a summary or excerpt (used by the snippet layout, for example)

has_readmore

Control whether a layout will display a 'Read More' permalink

has_date

Control whether a layout will display a date – used typically by snippets and blog layouts.

Clone this wiki locally