# wp-ultimate-post-grid/1.7.2/addons/custom-templates/templates/template.php

WP Ultimate Post Grid, version 1.7.2. 66 lines.

- Page: https://pluginprobe.com/plugins/wp-ultimate-post-grid/1.7.2/code/addons/custom-templates/templates/template.php
- Raw: https://pluginprobe.com/plugins/wp-ultimate-post-grid/1.7.2/raw/addons/custom-templates/templates/template.php
- Modified: 2015-04-15T08:46:56+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wp-ultimate-post-grid/1.7.2/code/addons/custom-templates/templates/template.php#L10-L20`.

```php
<?php

class WPUPG_Template {

    public $blocks;
    public $container;
    public $fonts;

    public function __construct( $blocks, $fonts = array() )
    {
        $this->fonts = $fonts;

        // Set object blocks before sorting to maintain index
        $this->blocks = $blocks;

        // Sort according to block order
        usort( $blocks, array( $this, 'sortByOrder' ) );

        // Generate children, children will be sorted correctly due to above sort
        foreach( $blocks as $block )
        {
            if( isset( $block->parent ) && isset( $block->row ) && isset( $block->column ) )
            {
                // Set container block, there should only be one
                if( $block->type == 'container' ) {
                    $this->container = $block;
                }
                // Add child to parent
                else
                {
                    $this->blocks[$block->parent]->add_child( $block );
                }
            }
        }

    }

    public function sortByOrder( $a, $b )
    {
        return $a->order > $b->order ? 1 : -1;
    }

    public function serialize()
    {
        return serialize( $this );
    }

    public function encode()
    {
        return base64_encode( $this->serialize() );
    }

    public function output_string( $post, $classes )
    {
        $args = array(
            'classes' => $classes,
        );

        return $this->container->output( $post, $args );
    }

    public function output( $post, $classes )
    {
        echo $this->output_string( $post, $classes );
    }
}
```
