/data/websites/webnews/web/app/themes/webnews/src/ViewModel/Post/Templates/Archive.php
'tags' => $this->getTags( $post ),
'label' => $label['text'],
'label_class' => $label['tipologia'],
'label_link' => $label['link'],
];
}
/**
* La versione di base ritorna la categoria
* del post
*
* @param WP_Post $post
* @return array
*/
protected function getLabel( $post ) {
$category = $this->getCategory( $post );
return [
'text' => $category->name,
'tipologia' => 'category',
'link' => get_term_link( $category )
];
}
/**
* Returns just the sizes needed for archives
*
* @param WP_Post $post
* @return array
*/
protected function getImage( $post ) {
$featuredImage = new FeaturedImage( $post->ID );
return $featuredImage->sizes(['extra_small', 'extra_small_x2', 'square', 'square_x2', 'minismall', 'minismall_x2', 'small', 'small_x2', 'medium', 'medium_x2' ]);
}
}
/data/websites/webnews/web/app/themes/webnews/src/ViewModel/Post/Templates/Archive.php
'tags' => $this->getTags( $post ),
'label' => $label['text'],
'label_class' => $label['tipologia'],
'label_link' => $label['link'],
];
}
/**
* La versione di base ritorna la categoria
* del post
*
* @param WP_Post $post
* @return array
*/
protected function getLabel( $post ) {
$category = $this->getCategory( $post );
return [
'text' => $category->name,
'tipologia' => 'category',
'link' => get_term_link( $category )
];
}
/**
* Returns just the sizes needed for archives
*
* @param WP_Post $post
* @return array
*/
protected function getImage( $post ) {
$featuredImage = new FeaturedImage( $post->ID );
return $featuredImage->sizes(['extra_small', 'extra_small_x2', 'square', 'square_x2', 'minismall', 'minismall_x2', 'small', 'small_x2', 'medium', 'medium_x2' ]);
}
}
/data/websites/webnews/web/app/themes/webnews/src/ViewModel/Post/Templates/Archive.php
<?php
namespace THEME\ViewModel\Post\Templates;
use THEME\ViewModel\Post\Content\FeaturedImage;
/**
* Pay attention this is the representation
* of a POST into an Archive contex\t
*
*/
class Archive extends Single implements iTemplate {
public function getPostData( $post ) {
$label = $this->getLabel($post->ID);
return [
'id' => $post->ID,
'title' => $post->post_title,
'excerpt' => $post->post_excerpt,
'link' => get_the_permalink( $post->ID ),
'image' => $this->getImage( $post ),
'tags' => $this->getTags( $post ),
'label' => $label['text'],
'label_class' => $label['tipologia'],
'label_link' => $label['link'],
];
}
/**
* La versione di base ritorna la categoria
* del post
*
* @param WP_Post $post
* @return array
*/
protected function getLabel( $post ) {
/data/websites/webnews/web/app/themes/webnews/src/ViewModel/Archive.php
$postTemplate = empty( $postTemplate ) ? $this->postTemplate : $postTemplate;
$args = array_merge( [
'posts_per_page' => Archive::ARCHIVE_POSTS_PER_PAGE,
'paged' => 0,
'post_status' => 'publish'
], $args );
// create the query for main contents
$query = new \WP_Query( $args );
$posts = $query->posts;
$tot_pages = $query->max_num_pages;
// as an array of posts
$posts = array_map( function ( $post ) use ($postTemplate) {
// structured as described by the current template
return $postTemplate->getPostData( $post );
}, $posts );
return (object) [ 'posts' => $posts, 'tot_pages' => $tot_pages ];
}
/**
* set the list of the components
* override this to add or remove components
*/
protected function initComponents() {
$this->components = [
'Pagination',
'Breadcrumbs',
'CustomTitle',
'Adv',
];
}
/data/websites/webnews/web/app/themes/webnews/src/ViewModel/Archive.php
*/
protected function doQuery( $args, $postTemplate = null) {
$postTemplate = empty( $postTemplate ) ? $this->postTemplate : $postTemplate;
$args = array_merge( [
'posts_per_page' => Archive::ARCHIVE_POSTS_PER_PAGE,
'paged' => 0,
'post_status' => 'publish'
], $args );
// create the query for main contents
$query = new \WP_Query( $args );
$posts = $query->posts;
$tot_pages = $query->max_num_pages;
// as an array of posts
$posts = array_map( function ( $post ) use ($postTemplate) {
// structured as described by the current template
return $postTemplate->getPostData( $post );
}, $posts );
return (object) [ 'posts' => $posts, 'tot_pages' => $tot_pages ];
}
/**
* set the list of the components
* override this to add or remove components
*/
protected function initComponents() {
$this->components = [
'Pagination',
'Breadcrumbs',
'CustomTitle',
'Adv',
/data/websites/webnews/web/app/themes/webnews/src/ViewModel/Home.php
// create the query for main contents
$args = [
'posts_per_page' => Archive::ARCHIVE_POSTS_PER_PAGE,
'paged' => $this->paged,
'post_type' => 'post',
'tax_query' => [ [
'taxonomy' => $this->svc_term->taxonomy,
'terms' => [ $this->svc_term->term_id ],
'operator' => 'NOT IN'
] ],
];
if ( !empty($this->tag_prodotti) ) {
$args[ 'tag__not_in ' ] = [ $this->tag_prodotti->term_id ];
}
$articles = $this->doQuery( $args, $this->postTemplate );
$this->data[ 'articles' ] = array_merge( $this->setFeatured(), $articles->posts );
$this->data[ 'tot_pages' ] = $articles->tot_pages;
$this->data[ 'reviews' ] = $this->setReviews();
//$this->data[ 'products' ] = $this->setProducts();
}
/**
* set the list of the components
* override this to add or remove components
*/
protected function initComponents() {
$this->components = [
'Pagination',
'Adv',
'OffersWidget',
/data/websites/webnews/web/app/themes/webnews/src/ViewModel/Archive.php
$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/webnews/web/app/themes/webnews/src/ViewModel/Home.php
/** @var string[] */
//protected $tags_to_exclude = [ 'offerte', 'manuali', 'speciale'];
function __construct() {
global $wp_query;
$this->tot_pages = $wp_query->max_num_pages;
$this->reviewTemplate = new ReviewTemplate();
$this->postsToExclude = [];
$this->tag_prodotti = get_term_by( 'slug', 'prodotti', 'post_tag' );
/// imposta il term di servizio
$this->svc_term = get_term_by( 'slug', HomeOptions::$svc_featured_term, HomeOptions::$svc_taxonomy );
parent::__construct();
}
/**
* Writes the basic page informations
*/
protected function setPageData() {
$blog_name = get_bloginfo();
$blog_url = get_home_url();
$this->data = [
'type' => 'home',
'infinite' => 'true',
'maxLoads' => 3,
'related_posts' => [
[ 'title' => $blog_name, 'url' => $blog_url . '/page/2/' ],
[ 'title' => $blog_name, 'url' => $blog_url . '/page/3/' ],
[ 'title' => $blog_name, 'url' => $blog_url . '/page/4/' ],
[ 'title' => $blog_name, 'url' => $blog_url . '/page/5/' ],
]
/data/websites/webnews/web/app/themes/webnews/index.php
<?php
use THEME\ViewModel\Home;
use Timber\Timber;
// load data
$home = ( new Home() )->getData();
$paged = (get_query_var('paged') !== null && get_query_var('paged') !== 0) ? get_query_var('paged') : 1;
$ajax = isset($_GET['is_ajax_request']);
switch($paged){
case 1 :
Timber::render( 'index.twig', $home );
break;
default:
if($ajax) Timber::render( 'index-ajax.twig', $home );
else Timber::render( 'index-paged.twig' , $home );
break;
}
/data/websites/webnews/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/webnews/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/webnews/web/index.php
<?php
/**
* WordPress View Bootstrapper
*/
define('WP_USE_THEMES', true);
require __DIR__ . '/wp/wp-blog-header.php';