PHP code example of bechwebbkonsult / wordpress-template-models

1. Go to this page and download the library: Download bechwebbkonsult/wordpress-template-models library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bechwebbkonsult / wordpress-template-models example snippets


class HomeTemplateModel extends TemplateModel
{
    public $terms = [];

    public function __construct()
    {
        foreach (get_terms(['taxonomy' => 'bf_calendar', 'hide_empty' => false]) as $term) {
            $term->url = get_term_link($term->term_id);
            $this->terms[] = $term;
        }
    }
}

use Bechwebb\TemplateModels\TemplateModelProvider;

$templateModelProvider = new TemplateModelProvider;
$templateModelProvider->register('/home.php', \App\TemplateModels\HomeTemplateModel::class);

 foreach ($terms as $term) : 

use Bechwebb\TemplateModels\TemplateModel;

class CalendarSidebarTemplateModel extends TemplateModel
{
    public $title = '';
    public $posts = [];

    public function __construct($title, $post_type)
    {
        $this->title = $title;

        foreach (get_posts((['post_type' => '$post_type']) as $post) {
            $post->url = get_post_permalink($post->ID);

            $this->posts[] = post;
        }
    }
}

$templateModelProvider->register('/theme-templates/calendar-sidebar.php', \App\TemplateModels\CalendarSidebarTemplateModel::class);

get_model_template('/theme-templates/calendar-sidebar.php', 'Sidebar title', 'bf_calendar');