Skip to content

Molecules

Michiel Tramper edited this page Aug 28, 2019 · 20 revisions

A molecule is a modular component or section of a website, such as a footer, header or grid of posts.

Each molecule has unique properties, besides the common properties you may give to each molecule. These are listed here. These properties also have default values.

Contrary to an atom, a molecule may contain several atoms inside itself. This is where the real power of a molecule lays, as you can display any of the atoms inside a molecule.

Rendering a Molecule

A set of properties is defined while rendering an atom in the following way:

MakeitWorkPress\WP_Components\Build::molecule( string $moleculename, array $properties );

The second parameter is the properties for the given atom. Properties are always in the form of an array.

The following gives an example for rendering a site header, which is fixed to the top and displays a logo and menu atom.

MakeitWorkPress\WP_Components\Build::molecule( 
    'header', 
    [
         'atoms' => [
              'logo' => [
                  'atom'       => 'logo', 
                  'properties' => [
                      'default' => ['src' => 'http://www.url.com/logo.jpg', 'height' => 80, 'width' => 240]
                   ]
              ],
              'menu' => [
                  'atom' => 'menu', 
                  'properties' => ['args' => ['theme_location' => 'main']]
              ]
         ], 
         'fixed' => true
    ] 
);

There is also a shorter function available:

wpc_molecule( 
    'header', 
    [
         'atoms' => [
              'logo' => [
                  'atom'       => 'logo', 
                  'properties' => [
                      'default' => ['src' => 'http://www.url.com/logo.jpg', 'height' => 80, 'width' => 240]
                   ]
              ],
              'menu' => [
                  'atom' => 'menu', 
                  'properties' => ['args' => ['theme_location' => 'main']]
              ]
         ], 
         'fixed' => true
    ] 
);

Rendering atoms inside a molecule

If a molecule supports to render atoms, they are often a property of that molecule. They are always formatted in the following way:

[
    'key_for_atom'   => [
        'atom'       => string $atomname,      // The name of the atom
        'properties' => array $atomproperties  // The properties for the given atom
    ]
]

To see this in action, please look to the example of the site header above.

 

Footer

Displays a site footer, usually the bottom part of a website. The footer consists of one section which may display the sidebar, and a lower socket section with can contain several atoms.

Property Type Description Default Values
attributes array The custom properties for the footer ['itemscope' => 'itemscope', 'itemtype' => 'http://schema.org/WPFooter']
atoms array The atoms displayed in the socket. See rendering atoms. []
container boolean Whether the footer's content should be contained inside a container or be full-width true
gridGap string The optional grid gap between the sidebars. Supports 'tiny', 'small', 'default', 'medium', 'large', 'huge' and 'none', 'default'
sidebars array Contains an array of sidebars, with sidebar names/ids as keys and grid classes as values. Grid classes support the grid classes as provided by WP Components. These are 'full', 'half', 'third', 'two-third', 'fourth', 'three-fourth' and 'fifth'. Also, see the example below. []

Example of rendering a footer

The following displays a footer with two sidebars and a socket with a copyright message floating left and a menu floating right.

MakeitWorkPress\WP_Components\Build::molecule( 
    'footer', 
    [
         'atoms' => [
              'copyright' => [
                  'atom'       => 'copyright', 
                  'properties' => ['float' => 'left', 'name'  => 'Organization Name']
              ],
              'menu' => [
                  'atom' => 'menu', 
                  'properties' => ['args' => ['theme_location' => 'footer'], 'float' => 'right']
              ]
         ], 
         'sidebars' => [
             'footer_one' => 'components-half-grid',
             'footer_two' => 'components-half-grid' 
         ]
    ] 
);

 

Header

Displays a site header

Property Type Description Default Values
atoms array The atoms displayed in the middle part of the header. See rendering atoms. []
attributes array The custom properties for the header ['class' => 'molecule-header-top', 'itemscope' => 'itemscope', 'itemtype' => 'http://schema.org/WPHeader']
container boolean Whether the header's content should be contained inside a container or be full-width true
fixed boolean Whether the header should stick to the top or not. true
headRoom boolean Whether the header should hide when scrolling down, but display when scrolling up. false
socketAtoms array The atoms displayed in the bottom part of the header. See rendering atoms. []
topAtoms array The atoms displayed in the top part of the header. See rendering atoms. []
transparent boolean Whether the header should be transparent or not. false

 

Post Footer

Displays the footer within a post article

Property Type Description Default Values
atoms array The atoms displayed in the post footer. See rendering atoms. []
container boolean Whether the post footer's content should be contained inside a container or be full-width true

 

Post Header

Displays the header within a post article

Property Type Description Default Values
atoms array The atoms displayed in the post header. See rendering atoms. ['title' => ['atom' => 'title', 'properties' => ['tag' => 'h1', 'attributes' => ['class' => 'entry-title']]]]
container boolean Whether the post headers's content should be contained inside a container of be full-width true
scroll boolean Whether to show a scroll down button at the bottom of the post header or not false

 

Posts

Display a grid or list of posts

Property Type Description Default Values
ajax boolean Whether to load paginated posts through ajax or not. true
attributes array The custom attributes for posts. See below
gridGap string The optional grid gap between the various posts. Supports 'tiny', 'small', 'default', 'medium', 'large', 'huge' and 'none', 'default'
infinite boolean Whether to load consecutive post pages through infinite scrolling or not false
pagination array The arguments for the pagination atom. ['type' => 'numbers']
postProperties array The properties for each post in the grid. See below
query object A WP_Query object containing the wanted posts ''
queryArgs array The arguments for querying a post, based upon the WP_Query class []
schema boolean Whether to display Microdata or not. Also removes schematic attributes. true
view string The style of the grids. Accepts list, grid or a custom class 'list'
wrapper string Custom class for the wrapper around posts ''

Default values for the attributes property

The following values are the default values for the attributes property

[
    'data'      => ['id' => 'molecule-posts'],  // Used to match requests for ajax. Should be unique
    'itemscope' => 'itemscope',             
    'itemtype'  => 'http://schema.org/Blog' 
]

Default values for the postProperties property

The following values are the default values for the postProperties property. This property determines how each of the posts looks like in the grid.

[
    // The attributes for each post
    'attributes'    => [
            'itemprop'  => 'blogPost',
            'itemscope' => 'itemscope',
            'itemtype'  => 'http://schema.org/BlogPosting'            
    ],
    // Indicates if we put author and other schema.org data within a blog bost
    'blogSchema'    => true,                            
    // Accepts a set of atoms for within the content
    'contentAtoms'  => [
        'content' => [ 
            'atom'          => 'content', 
            'properties'    => ['type' => 'excerpt'] 
        ]
    ],   
    // Accepts a set of atoms for use in the post footer     
    'footerAtoms'   => [                              
            'button' => [
                'atom'          => 'button', 
                'properties'    => ['float' => 'right', 'label' => __('View post', 'components'), 'link' => 'post', 'size' => 'small'] 
            ]
    ],  
    // The default grid. Accepts 'full', 'half', 'third', 'fourth', 'fifth' or an array with a pattern of these
    'grid' => '',    
     // Accepts a set of atoms for use in the post header    
    'headerAtoms'   => [                              
        'title' => [
            'atom'          => 'title', 
            'properties'    => ['attributes' => ['itemprop' => 'name headline', 'class' => 'entry-title'], 'tag' => 'h2', 'link' => 'post' ] 
       ] 
   ],  
   // The post image  
   'image'         => [ 'link' => 'post', 'size' => 'medium', 'enlarge' => true ],   
    // The logo that is used in microschemes and rich snippets 
   'logo'          => 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==', 
   // The name of the organization that is used in microschemes and rich snippets
   'organization'  => get_bloginfo('name')
]

 

Slider

Displays a slider with custom slide content based upon Tinyslider

Property Type Description Default Values
attributes array The custom attributes for posts. ['data' => ['id' => uniqid()]]
options array The Tinyslider options for the slider See below
scroll boolean Adds a scroll button to the bottom of the slider. false
slides array The actual slides, an array with video, image, atoms and attributes keys. See the example below. []
thumbnailSize string The default size for thumbnails, such as 'thumbnail'. If set, thumbnail navigation is added to the slides. Slides should have an image in the form of attachment IDs. ''

Default values for the options property

These are the default values for the options property. These options reflect the properties as they are supported by Tinyslider

[
        'arrowKeys'         => true,
        'autoHeight'        => true,
        'controlsText'      => ['<i class="fa fa-angle-left"></i>', '<i class="fa fa-angle-right"></i>'],	
        'navPosition'       => 'bottom',
        'mode'              => 'carousel',      // Type of animation
        'speed'             => 500,             // Speed of animation
]

Example for rendering a usual slider

This example renders a slider with three slides, once with an image and a white background, one with a video and one with a description and button atom

    MakeitWorkPress\WP_Components\Build::molecule( 
        'slider',
        [
            'slides' => [
                 'slider_one' => [
                     'attributes' => ['background' => '#FFFFFF', 'class' => 'slider-one'], 
                     'image'      => ['image' => 71] // These can be the properties for an image atom
                 ],
                 'slider_two' => [
                     'video'      => ['video' => 'http://v.io/v.mp4'] // These can be the propertyies for a video atom
                 ],
                 'slider_three' => [
                     'attributes' => ['background' => '#FFFFFF', 'class' => 'slider-three'], 
                     'atoms'      => [
                          'description' => ['atom' => 'description', 'properties' => ['description' => 'Description']]
                          'button'      => ['atom' => 'button', 'properties' => ['label' => 'Label']]
                     ] 
                 ]
            ]
        ]
    );

Example for rendering a slider with thumbnails

The following shows a slider with two large images and thumbnail navigation. This navigation has the same images but in thumbnail size.

    MakeitWorkPress\WP_Components\Build::molecule( 
        'slider',
        [
            'slides' => [
                 'slider_one' => [
                     'image'      => ['image' => 71, 'size' => 'large'] // These can be the properties for an image atom
                 ],
                 'slider_two' => [
                     'image'      => ['image' => 71, 'size' => 'large'] // These can be the properties for an image atom
                 ],
            ],
            'thumbnailSize' => 'thumbnail'
        ]
    );

Clone this wiki locally