/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Archive/Templates/Archive.php
namespace THEME\ViewModel\Archive\Templates;
/**
* Pay attention this is the representation
* of a Term into an Archive contex\t
*
*/
class Archive implements iTemplate {
/**
* ritorna il sottoinsieme di dati necessario per il termine
*
* @param object $term
* @return array
*/
public function getTermData( $term ) {
return [
'id' => $term->term_id,
'taxonomy' => $term->taxonomy,
'title' => $term->name,
'excerpt' => $term->description,
'link' => get_term_link( $term , $term->taxonomy ),
'parent' => $term->parent,
'meta' => $this->getCustomFields( $term ),
];
}
/**
* Returns acf custom fields for the given term
*
* @param WP_Term $term
* @return array
*/
protected function getCustomFields( $term ) {
$fieldsRetrieved = [];
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Archive/Templates/Archive.php
namespace THEME\ViewModel\Archive\Templates;
/**
* Pay attention this is the representation
* of a Term into an Archive contex\t
*
*/
class Archive implements iTemplate {
/**
* ritorna il sottoinsieme di dati necessario per il termine
*
* @param object $term
* @return array
*/
public function getTermData( $term ) {
return [
'id' => $term->term_id,
'taxonomy' => $term->taxonomy,
'title' => $term->name,
'excerpt' => $term->description,
'link' => get_term_link( $term , $term->taxonomy ),
'parent' => $term->parent,
'meta' => $this->getCustomFields( $term ),
];
}
/**
* Returns acf custom fields for the given term
*
* @param WP_Term $term
* @return array
*/
protected function getCustomFields( $term ) {
$fieldsRetrieved = [];
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Archive.php
/**
* Add the data of the current term or post type or author
*
* @return void
*/
protected function setTerm( $object_type = 'WP_Term' ) {
switch( $object_type ){
case 'WP_Term': $term = $this->term; break;
case 'WP_Post_Type': $term = $this->post_type; break;
case 'WP_User': $term = $this->author; break;
/// home page
default: $term = null;
}
$this->data['term'] = empty( $term ) ? [] : $this->archiveTemplate->getTermData( $term );
}
/**
* set the posts list as articles array using
* the standard wp_query
*
* AND SET the total pages to data ( lo so qui bisognerebbe architettarlo un mo meglio)
*
* @return void
*/
protected function setArticles() {
// create the query for main contents
$args = [
'paged' => $this->paged,
'post_type' => empty( $this->post_type) ? 'notizie' : $this->post_type->name,
];
if( !empty( $this->term ) ) {
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Archive.php
function __construct( $postTemplate = 'Archive', $archiveTemplate = 'Archive' ) {
$queried_object = get_queried_object();
$obj_type = empty( $queried_object ) ? '' : get_class( $queried_object ) ;
$this->term = ( $obj_type == 'WP_Term' ) ? $queried_object : null;
$this->post_type = ( $obj_type == 'WP_Post_Type' ) ? $queried_object : null;
$this->author = ( $obj_type == 'WP_User' ) ? $queried_object : null;
parent::__construct();
// set the postTemplate (default 'Archive')
$this->postTemplate = $this->postTemplateFactory( $postTemplate );
// set the archiveTemplate (default 'Archive')
$this->archiveTemplate = $this->archiveTemplateFactory( $archiveTemplate );
// add the current term's data
$this->setTerm( $obj_type );
// add the articles to data
$this->setArticles();
// set the components list into property
// $components
$this->initComponents();
// add all the default components
$this->setComponents();
}
/**
* Writes the basic page informations
*/
protected function setPageData(){
$this->data = [
'type' => 'archive',
'infinite' => 'true',
/data/websites/telefonino/web/app/themes/telefonino/archive.php
<?php
use THEME\ViewModel\Archive;
use THEME\Utils\Timber;
$paged = (get_query_var('paged') && get_query_var('paged') !== 0) ? get_query_var('paged') : 1;
$data = ( new Archive() ) ->getData();
$data['page'] = $paged;
$template = $paged == 1 ? 'archive.twig' : 'archive-paged.twig';
Timber::render( $template, $data );
/data/websites/telefonino/web/wp/wp-includes/template-loader.php
}
break;
}
}
if ( ! $template ) {
$template = get_index_template();
}
/**
* Filters the path of the current template before including it.
*
* @since 3.0.0
*
* @param string $template The path of the template to include.
*/
$template = apply_filters( 'template_include', $template );
if ( $template ) {
include $template;
} elseif ( current_user_can( 'switch_themes' ) ) {
$theme = wp_get_theme();
if ( $theme->errors() ) {
wp_die( $theme->errors() );
}
}
return;
}
/data/websites/telefonino/web/wp/wp-blog-header.php
<?php
/**
* Loads the WordPress environment and template.
*
* @package WordPress
*/
if ( ! isset( $wp_did_header ) ) {
$wp_did_header = true;
// Load the WordPress library.
require_once __DIR__ . '/wp-load.php';
// Set up the WordPress query.
wp();
// Load the theme template.
require_once ABSPATH . WPINC . '/template-loader.php';
}
/data/websites/telefonino/web/index.php
<?php
/**
* WordPress View Bootstrapper
*/
define('WP_USE_THEMES', true);
require __DIR__ . '/wp/wp-blog-header.php';