Beispiel #1
0
 static function get_projects()
 {
     if (self::is_client()) {
         return array();
     }
     return Timber::get_posts(array('orderby' => 'title', 'post_type' => 'project', 'order' => 'ASC'));
 }
 /**
  * get_posts
  *
  * @return mixed
  */
 protected function get_posts()
 {
     if (empty($this->posts)) {
         $this->posts = \Timber::get_posts();
     }
     return $this->posts;
 }
/**
 * Timber-specific functions
 */
function add_to_context($data)
{
    /* this is where you can add your own data to Timber's context object */
    $data['qux'] = 'I am a value set in your functions.php file';
    $data['theme_url'] = get_template_directory_uri();
    // load ACF values
    if (function_exists('get_field')) {
        $data['slogan'] = get_field('slogan', 'option');
        $data['featured_content'] = array();
        $data['featured_content'] = Timber::get_posts(get_field('featured_content', 'option'));
        // Events can have multiple instances so we fix that this way.
        foreach ($data['featured_content'] as $key => $feature) {
            if ($feature->ID === $previous_ID) {
                unset($data['featured_content'][$key]);
            } else {
                if (stristr($feature->class, "recurring")) {
                    $feature->recurring = date("l @ g:ia", strtotime($feature->post_date)) . "";
                }
            }
            $previous_ID = $feature->ID;
        }
    }
    $data['menu'] = array('primary' => new TimberMenu('primary'), 'secondary' => new TimberMenu('secondary'), 'social' => new TimberMenu('social'), 'footer' => new TimberMenu('footer'));
    return $data;
}
Beispiel #4
0
 /**
  * Determine the context that will be used by the content() method
  */
 public function context()
 {
     global $wp_query;
     $context = Maera()->cache->get_context();
     $post = new TimberPost();
     $context['post'] = $post;
     $context['posts'] = Timber::get_posts();
     // Compatibility hack or plugins that change the content.
     if ($this->plugins_compatibility()) {
         $context['content'] = maera_get_echo('the_content');
     }
     if (is_singular()) {
         $context['wp_title'] .= ' - ' . $post->title();
     }
     if (is_search()) {
         $context['title'] = __('Search results for ', 'maera') . get_search_query();
     }
     if (is_archive() || is_home()) {
         $context['posts'] = Timber::query_posts(false, 'TimberPost');
         $context['title'] = get_the_archive_title();
         if (is_author()) {
             $author = new TimberUser($wp_query->query_vars['author']);
             $context['author'] = $author;
         }
     }
     if (class_exists('WooCommerce')) {
         global $product;
         $context['product'] = $product;
     }
     return $context;
 }
Beispiel #5
0
 public function load_view()
 {
     $context = Timber::get_context();
     $context['posts'] = Timber::get_posts();
     $context['data'] = $this->data;
     $context['constants'] = get_slate_constants();
     Timber::render(theme_views . '/archive.twig', $context);
 }
 /**
  * get_posts
  *
  * @return mixed
  */
 protected function get_posts()
 {
     $args = array('author' => $this->get_author()->id, 'paged' => get_query_var('paged') ? get_query_var('paged') : 1);
     if (empty($this->posts)) {
         $this->posts = \Timber::get_posts($args);
     }
     return $this->posts;
 }
Beispiel #7
0
 public function get_sorted_projects($args = array())
 {
     $default_args = $this->get_query_args();
     $args = array_merge($default_args, $args);
     query_posts($args);
     $projects = Timber::get_posts($args);
     $this->sort_list($projects);
     return $projects;
 }
 function testGetPostsArrayCount()
 {
     $pids = array();
     $pids[] = $this->factory->post->create();
     $pids[] = $this->factory->post->create();
     $pids[] = $this->factory->post->create();
     $posts = Timber::get_posts($pids);
     $this->assertEquals(3, count($posts));
 }
Beispiel #9
0
 public function testimonials()
 {
     $cats = wp_get_post_terms($this->ID, 'areas');
     //print_r($cats);
     $tax = array(array('taxonomy' => 'areas', 'field' => 'slug', 'terms' => $cats[0]->slug, 'operator' => 'IN'));
     //print_r($tax);
     $args = array('post_type' => 'testimonials', 'tax_query' => $tax, 'orderby' => 'rand');
     $tests = Timber::get_posts($args);
     return $tests;
 }
Beispiel #10
0
 function add_to_context($context)
 {
     $context['stuff'] = 'I am a value set in your functions.php file';
     $context['notes'] = 'These values are available everytime you call Timber::get_context();';
     $context['primary_nav'] = new TimberMenu('Primary Nav');
     $context['footer_nav'] = new TimberMenu('Footer Nav');
     $args = array('post_type' => 'products');
     $context['products'] = Timber::get_posts($args);
     $context['site'] = $this;
     return $context;
 }
 /**
  * Render the menu widget.
  * @todo TODO
  * @since 1.0.0
  */
 function widget($args, $instance)
 {
     extract($args);
     $query_args = array('post_type' => 'restaurant_item', 'posts_per_page' => $instance['per_page']);
     $widget = array('title' => apply_filters('widget_title', $instance['title']), 'show_price' => $instance['show_price'], 'show_featured_images' => $instance['show_featured_images'], 'show_tags' => $instance['show_tags'], 'show_menu_link' => $instance['show_menu_link'], 'before_widget' => $before_widget, 'after_widget' => $after_widget, 'before_title' => $before_title, 'after_title' => $after_title);
     $context = Maera()->cache->get_context();
     $context['menu_item'] = Timber::query_post();
     $context['menu_items'] = Timber::get_posts($query_args);
     $context['widget'] = $widget;
     Timber::render('menu.twig', $context, Maera()->cache->cache_duration());
     wp_reset_postdata();
 }
 /**
  * Render the slider widget.
  * @todo TODO
  * @since 1.0.0
  */
 function widget($args, $instance)
 {
     extract($args);
     $query_args = array('post_type' => 'slide', 'posts_per_page' => $instance['per_page'], 'offset' => $instance['offset']);
     $widget = array('interval' => $instance['interval'], 'pause' => $instance['pause'], 'wrap' => $instance['wrap'], 'parallax' => $instance['parallax'], 'second_image' => $instance['second_image'], 'before_widget' => $before_widget, 'after_widget' => $after_widget, 'before_title' => $before_title, 'after_title' => $after_title);
     $context = Maera()->cache->get_context();
     $context['slide'] = Timber::query_post();
     $context['slides'] = Timber::get_posts($query_args);
     $context['widget'] = $widget;
     Timber::render('slider.twig', $context, Maera()->cache->cache_duration());
     wp_reset_postdata();
 }
 /**
  * Render the widget on the front end.
  * @todo TODO
  * @since 1.0.0
  */
 function widget($args, $instance)
 {
     extract($args);
     if (isset($instance['term']) && 'any' != $instance['term']) {
         $tax_query = array(array('taxonomy' => $instance['taxonomy'], 'terms' => $instance['term']));
     } else {
         $tax_query = '';
     }
     $query_args = array('post_type' => $instance['post_type'], 'tax_query' => $tax_query, 'posts_per_page' => $instance['per_page'], 'offset' => $instance['offset']);
     $widget = array('title' => apply_filters('widget_title', $instance['title']), 'thumb' => $instance['thumb'], 'thumb_float' => $instance['thumb_float'], 'thumb_width' => $instance['thumb_width'], 'thumb_height' => $instance['thumb_height'], 'excerpt_length' => $instance['excerpt_length'], 'more_text' => $instance['more_text'], 'post_title_size' => $instance['post_title_size'], 'before_widget' => $before_widget, 'after_widget' => $after_widget, 'before_title' => $before_title, 'after_title' => $after_title);
     $context = Maera()->cache->get_context();
     $context['post'] = Timber::query_post();
     $context['posts'] = Timber::get_posts($query_args);
     $context['widget'] = $widget;
     Timber::render('widget-extended-posts.twig', $context, Maera()->cache->cache_duration());
     wp_reset_query();
 }
 /**
  * Modify the Timber global context
  * @param  [type] $context [description]
  * @return [type]          [description]
  */
 function maera_res_context($context)
 {
     $context['currency'] = get_theme_mod('currency', '$');
     $context['facebook_link'] = get_theme_mod('facebook_link', 'http://facebook.com/');
     $context['twitter_link'] = get_theme_mod('twitter_link', 'http://twitter.com/');
     $context['googleplus_link'] = get_theme_mod('googleplus_link', 'http://plus.google.com/');
     $context['youtube_link'] = get_theme_mod('youtube_link', 'http://youtube.com');
     $context['menu_sections'] = Timber::get_terms('restaurant_item_menu_section');
     $context['sidebar']['section_1'] = Timber::get_widgets('section_1');
     $context['sidebar']['section_2'] = Timber::get_widgets('section_2');
     $context['sidebar']['section_3'] = Timber::get_widgets('section_3');
     $context['sidebar']['section_4'] = Timber::get_widgets('section_4');
     $context['sidebar']['section_5'] = Timber::get_widgets('section_5');
     $context['sidebar']['footer'] = Timber::get_widgets('footer');
     if (is_post_type_archive('restaurant_item') && rp_is_restaurant()) {
         $query_args = array('post_type' => 'restaurant_item', 'posts_per_page' => 999, 'order' => get_theme_mod('restaurant_order', 'ASC'), 'order_by' => get_theme_mod('restaurant_order_by', 'ID'));
         $context['menu_item'] = Timber::query_post();
         $context['menu_items'] = Timber::get_posts($query_args);
     }
     return $context;
 }
Beispiel #15
0
 /** FUNCTION getRoll 
  * returns string of HTML Slides
  **/
 public static function getRoll($temp = null, $args = null, $posts = null)
 {
     $context = Timber::get_context();
     if ($posts) {
         foreach ($posts as $post) {
             $post->post_excerpt = $post->post_excerpt ? $post->post_excerpt : wp_trim_words($post->post_content, 55);
             $post->post_thumbnail = get_the_post_thumbnail($post->ID, 'medium');
             $newPosts[] = $post;
         }
         $posts = $newPosts;
         $context['content'] = $posts;
     } else {
         if ($args) {
             $context['content'] = Timber::get_posts($args);
         } else {
             $context['content'] = new TimberPost();
         }
     }
     $template = $temp ? $temp : 'content';
     return self::getView($context, $template);
 }
 public static function do_load_more_posts()
 {
     $args = $_GET['args'];
     $template = $_GET['template'];
     if (preg_match('/,/', $args['post_type'])) {
         $post_types = explode(',', $args['post_type']);
         $args['post_type'] = $post_types;
     }
     $data = Timber::get_context();
     $posts = Timber::get_posts($args);
     if (empty($posts)) {
         echo 0;
         die;
     }
     $i = 1;
     foreach ($posts as $post) {
         $data['post'] = $post;
         $data['loop']['index'] = $i;
         Timber::render('partials/' . $template . '.twig', $data);
         $i = $i + 1;
     }
     die;
 }
Beispiel #17
0
 /**
  * Render the carousel template
  *
  */
 public static function render($template = 'carousel.twig', $query = array(), $width = 1140, $height = 500, $slick = array())
 {
     if (!isset($query['post_type'])) {
         $query['post_type'] = 'slide';
     }
     // uniquely identify each slider on the page
     static $slider_id = 0;
     $slider_id++;
     $slides = \Timber::get_posts($query);
     foreach ($slides as &$slide) {
         $slide->height = $height;
         $slide->width = $width;
         apply_filters('slick_slide', $slide);
     }
     $carousel['id'] = sprintf("%s-carousel-%s", $query['post_type'], $slider_id);
     $carousel['slides'] = $slides;
     if (count($slides)) {
         if ($slick) {
             $carousel['options'] = $slick;
         }
         return \Timber::compile($template, $carousel);
     }
 }
<?php

/**
 * The Template for displaying all single posts
 *
 * Methods for TimberHelper can be found in the /functions sub-directory
 *
 * @package  WordPress
 * @subpackage  Timber
 * @since    Timber 0.1
 */
$context = Timber::get_context();
$query = array('orderby' => 'meta_value_num', 'order' => 'asc', 'posts_per_page' => 12, 'post_type' => 'avaliacao', 'meta_query' => array(array('key' => 'ordem')));
$context['posts'] = Timber::get_posts($query);
$category_slug = get_query_var('category_name');
$obj_category = get_category_by_slug($category_slug);
$context['step_avaliacao'] = 'step_selected';
$context['show_step_2'] = true;
$context['nome_projeto'] = $obj_category->name;
$context['id_projeto'] = $obj_category->term_id;
$context['slug_projeto'] = $obj_category->slug;
$context['cor_projeto'] = get_tax_meta($obj_category->term_id, 'cda_color_field_id');
$context['username'] = get_query_var('username');
if (get_query_var('username')) {
    $current_user = get_user_by('login', get_query_var('username'));
    $context['profile'] = $current_user;
    $context['compartilhar_imagem'] = get_stylesheet_directory_uri() . '/assets/images/avaliacao_share_facebook_geral.jpg';
} else {
    global $current_user;
    get_currentuserinfo();
    $context['profile'] = $current_user;
<?php

/**
 * The main template file
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file
 *
 * Methods for TimberHelper can be found in the /functions sub-directory
 *
 * @package 	WordPress
 * @subpackage 	Timber
 * @since 		Timber 0.1
 */
if (!class_exists('Timber')) {
    echo 'Timber not activated. Make sure you activate the plugin in <a href="/wp-admin/plugins.php#timber">/wp-admin/plugins.php</a>';
}
$context = Timber::get_context();
$context['posts'] = Timber::get_posts(array('orderby' => 'ID'));
//var_dump($categories);
//$context['categories'] = $categories;
$templates = array('index.twig');
if (is_home()) {
    array_unshift($templates, 'home.twig');
}
Timber::render('index.twig', $context);
Beispiel #20
0
<?php

/**
 * The main template file
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists
 *
 * Methods for TimberHelper can be found in the /lib sub-directory
 *
 * @package  WordPress
 * @subpackage  Timber
 * @since   Timber 0.1
 */
if (!class_exists('Timber')) {
    echo 'Timber not activated. Make sure you activate the plugin in <a href="/wp-admin/plugins.php#timber">/wp-admin/plugins.php</a>';
    return;
}
$context = Timber::get_context();
$context['posts'] = Timber::get_posts();
$context['foo'] = 'bar';
$templates = array('index.twig');
if (is_home()) {
    array_unshift($templates, 'home.twig');
}
Timber::render($templates, $context);
Beispiel #21
0
$context['lang_class'] = get_field('language', 'options');
$context['lang_name'] = get_field('language_name', 'options');
$context['ga'] = get_field('google_analytics_code', 'options');
$context['canon'] = get_field('canonical_link', 'options');
$context['usp_title'] = get_field('usp_title', 'options');
$context['menu_item_1'] = get_field('main_menu_item_1', 'options');
$context['menu_item_2'] = get_field('main_menu_item_2', 'options');
$context['menu_item_3'] = get_field('main_menu_item_3', 'options');
$context['footer_text'] = get_field('footer_text', 'options');
$context['intro'] = new TimberPost(39);
// Replace id with proper id for Intro Page.
$context['local'] = new TimberPost(199);
$context['about'] = new TimberPost(35);
$context['trynow'] = new TimberPost(47);
$context['newsletter'] = new TimberPost(104);
$context['usps'] = Timber::get_posts('post_type=usps&post_status=publish&orderby=menu_order&order=ASC');
$context['usps_categories'] = Timber::get_terms('post_tag', array('hide_empty' => false));
$context['testimonials'] = Timber::get_posts('post_type=testimonials&post_status=publish&orderby=menu_order&order=ASC');
$context['support'] = Timber::get_posts('post_type=support&post_status=publish&orderby=menu_order&order=ASC');
$context['menu_eu'] = new TimberMenu('eur_menu');
$context['menu_usa'] = new TimberMenu('usa_menu');
$context['menu_aus'] = new TimberMenu('aus_menu');
$context['menu_afr'] = new TimberMenu('afr_menu');
$context['menu_asi'] = new TimberMenu('asi_menu');
$context['menu_mid'] = new TimberMenu('mid_menu');
$context['menu_other'] = new TimberMenu('other_menu');
$templates = array('index.twig');
if (is_home()) {
    array_unshift($templates, 'home.twig');
}
Timber::render($templates, $context);
Beispiel #22
0
<?php

/**
* Title: taxonomy-databases template.
*
* Description: Defines default template of Databases.
*
*/
require 'config.php';
$context = Timber::get_context();
$context['robot_index'] = $_ENV['ROBOT_INDEX'];
$context['robot_index'] = $_ENV['ROBOT_INDEX'];
$language = substr($context['site']->language, 0, 2);
$domain = $config['profile_map'][$currentCategory->description];
$dbUrl = $language === 'fr' ? '\\/bases-de-donnees\\/' : '\\/data-bases\\/';
$context['ebsco_widget'] = sprintf('[ebsco_widget domain="%s" language="%s" db_url="%s"]', $domain, $language, $dbUrl);
$context['bibcnrs_header'] = sprintf('[bibcnrs_header language="%s"]', $language);
$context['domain'] = (array) $wp_query->queried_object;
$args = array('showposts' => -1, 'post_type' => 'database', 'tax_query' => array(array('taxonomy' => 'databases', 'field' => 'slug', 'terms' => $context['domain']['slug'])), 'orderby' => 'post_title', 'order' => 'ASC');
$context['terms'] = get_terms('databases');
$context['origin'] = Timber::get_posts($args);
Timber::render('taxonomy-databases.twig', $context);
<?php

/*
Template Name: Mitarbeiter
*/
$context = Timber::get_context();
$post = new TimberPost();
$context['post'] = $post;
$mitarbeiter = Timber::get_posts(['post_type' => 'mitarbeiter', 'order_by' => 'title', 'order' => 'ASC']);
$context['mitarbeiter'] = $mitarbeiter;
Timber::render(array('page-mitarbeiter.twig', 'page.twig'), $context);
Beispiel #24
0
<?php

/**
 * Enables Timber Integration with Woocommerce, see https://github.com/timber/timber/wiki/WooCommerce-Integration
 */
$context = Timber::get_context();
$context['sidebar'] = Timber::get_widgets('shop-sidebar');
if (is_singular('product')) {
    $context['post'] = Timber::get_post();
    $product = get_product($context['post']->ID);
    $context['product'] = $product;
    Timber::render('woocommerce/single-product.twig', $context);
} else {
    $posts = Timber::get_posts();
    $context['products'] = $posts;
    if (is_product_category()) {
        $queried_object = get_queried_object();
        $term_id = $queried_object->term_id;
        $context['category'] = get_term($term_id, 'product_cat');
        $context['title'] = single_term_title('', false);
    }
    Timber::render('woocommerce/archive.twig', $context);
}
<?php

/*
Template Name: Blogue
*/
global $post;
$context = Timber::get_context();
$post = new TimberPost();
// Set context
$context = array_merge($context, array('posts' => Timber::get_posts(array('posts_per_page' => 10))));
Timber::render('posts/list.twig', $context);
Beispiel #26
0
 /**
  * html_sitemap
  *
  * @param array $post_types
  */
 public function html_sitemap($atts = array())
 {
     $atts = shortcode_atts(array('post_type' => 'page'), $atts);
     $data['posts'] = \Timber::get_posts(array('numberposts' => -1, 'post_type' => $atts['post_type'], 'post_status' => 'publish'));
     return \Timber::compile('sitemap-html.twig', $data);
 }
 function testPaginationInCategory($struc = '/%postname%/')
 {
     global $wp_rewrite;
     $wp_rewrite->permalink_structure = $struc;
     update_option('permalink_structure', $struc);
     $no_posts = $this->factory->post->create_many(25);
     $posts = $this->factory->post->create_many(31);
     $news_id = wp_insert_term('News', 'category');
     foreach ($posts as $post) {
         wp_set_object_terms($post, $news_id, 'category');
     }
     $this->go_to(home_url('/category/news'));
     $post_objects = Timber::get_posts(false);
     $pagination = Timber::get_pagination();
     //need to complete test
 }
    $search_args = get_post_query_args('esdeveniment', SearchQueryType::Search, $search);
    $args = wp_parse_args($search_args, $wp_query->query);
    //search + active args
    $date_filter_args = get_post_query_args('esdeveniment', SearchQueryType::FilteredDate, $filterdate);
    $args = wp_parse_args($date_filter_args, $args);
    //all filters applied
    $date_filter_args = get_post_query_args('esdeveniment', SearchQueryType::FilteredTema, $tema);
    $args = wp_parse_args($date_filter_args, $args);
    //all filters applied
    $context_holder['selected_filter_tema'] = $tema;
    $context_holder['selected_filter_data'] = $filter;
    $context_holder['cerca'] = $search;
    $title = 'Esdeveniments - ';
    !empty($search) ? $title .= 'cerca: ' . $search . ' - ' : '';
    !empty($tema) ? $title .= 'tema: ' . get_term_name_by_slug($tema, 'esdeveniment_cat') . ' - ' : '';
    !empty($filter) ? $title .= 'data: ' . get_the_filter_date_name($filter) . ' - ' : '';
    $title .= 'Softcatalà';
} else {
    $title = 'Esdeveniments - Softcatalà';
    $description = 'Esdeveniments relacionats amb el món de la tecnologia i el català.';
    $args = $wp_query->query;
}
//Posts and pagination
query_posts($args);
$context_holder['posts'] = Timber::get_posts($args);
$context_holder['pagination'] = Timber::get_pagination();
//Context initialization
$context_filterer = new SC_ContextFilterer($context_holder);
$context_overrides = array('title' => $title, 'description' => $description);
$context = $context_filterer->get_filtered_context($context_overrides, false);
Timber::render($templates, $context);
<?php

$issue = get_term_by('slug', get_query_var('issue'), 'issue');
$digital_only = get_field('digital_only', $issue);
$args = array('post_type' => 'sa-article', 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => 'issue', 'field' => 'slug', 'terms' => $issue->slug)), 'orderby' => 'menu_order', 'order' => 'ASC');
$articles = Timber::get_posts($args);
$data['issue'] = $issue;
$data['articles'] = $articles;
Beispiel #30
0
<?php

$data = Timber::get_context();
$data['posts'] = Timber::get_posts();
$data['page'] = 'page';
$data['slideshow'] = $get_slideshow();
$data['config'] = $get_config();
$data['menu'] = new TimberMenu();
// render using Twig template index.twig
Timber::render('page-404.twig', $data);