function in_news_int($atts, $content = null) { extract(shortcode_atts(array('title' => '', 'subtitle' => '', 'link' => '/'), $atts)); $limit_show_news = 100; $args = array('posts_per_page' => $limit_show_news, 'post_type' => 'post', 'meta_key' => 'is_video', 'orderby' => 'is_video', 'order' => 'DESC'); if (isset($atts['filter_car_emergence']) && $atts['filter_car_emergence'] == 1) { $args['tax_query'] = array('relation' => 'AND', array('taxonomy' => 'category', 'field' => 'term_id', 'terms' => 5)); } $query = new WP_Query($args); $post_list = ''; while ($query->have_posts()) { $query->the_post(); $atts['thumbnail'] = get_the_post_thumbnail(get_the_ID(), 'post-home-thumbnail'); $atts['categories'] = get_the_category(); $atts['class_categories_id'] = ''; $atts['class_categories_slug'] = ''; foreach ($atts['categories'] as $key => $category) { if ($category->parent == 4) { $atts['class_categories_id'] .= ' category-id-' . $category->term_id; $atts['class_categories_slug'] .= ' category-slug-' . $category->slug; unset($atts['categories'][$key]); } } $atts['title'] = get_the_title(); $atts['content'] = get_the_content(); $atts['permalink'] = get_permalink(); $post_list .= Timber::compile('post.twig', $atts); } $data['post_content'] = $post_list; $out = Timber::compile('template.twig', $data); return $out; }
function testGetWithQueryString() { $other_term = $this->factory->term->create(array('name' => 'Bogus Term')); $term_id = $this->factory->term->create(array('name' => 'My Term')); $terms = Timber::get_terms('term_id=' . $term_id); $this->assertEquals($term_id, $terms[0]->ID); $terms = Timber::get_terms('post_tag'); $this->assertEquals(2, count($terms)); $terms = Timber::get_terms(); $this->assertEquals(3, count($terms)); $terms = Timber::get_terms('categories'); $this->assertEquals(1, count($terms)); $terms = Timber::get_terms(array('tag')); $this->assertEquals(2, count($terms)); $query = array('taxonomies' => array('category')); $terms = Timber::get_terms($query); $this->assertEquals('Uncategorized', $terms[0]->name); $query = array('tax' => array('category')); $terms = Timber::get_terms($query); $this->assertEquals('Uncategorized', $terms[0]->name); $query = array('taxs' => array('category')); $terms = Timber::get_terms($query); $this->assertEquals('Uncategorized', $terms[0]->name); $query = array('taxonomy' => array('category')); $terms = Timber::get_terms($query); $this->assertEquals('Uncategorized', $terms[0]->name); $next_term = $this->factory->term->create(array('name' => 'Another Term')); $terms = Timber::get_terms('post_tag', 'term_id=' . $next_term); $this->assertEquals('Another Term', $terms[0]->name); $terms = Timber::get_terms(array($next_term, $term_id)); $this->assertEquals(2, count($terms)); $this->assertEquals('My Term', $terms[1]->name); }
/** * 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; }
/** * add_to_context * * Add available sidebars to the Timber context * * @param $context * * @return array */ public function add_to_context($context) { foreach ($this->sidebars as $key => &$sidebar) { $context["widget_{$key}"] = \Timber::get_widgets($sidebar['id']); } return $context; }
public function form($instance) { $context = \Timber::get_context(); $context['title'] = !empty($instance['title']) ? $instance['title'] : __('Test', self::I18N_DOMAIN); $context['widget'] = $this; \Timber::render('timber-test-widget-form.twig', $context); }
public function load_view() { $context = Timber::get_context(); $context['data'] = $this->data; $context['constants'] = get_slate_constants(); Timber::render(theme_views . '/single.twig', $context); }
/** * 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; }
/** * Renders the given template with a context using timber * * @param $template * @param $context * @throws \RuntimeException * @author Tim Perry */ protected function render($template, $context) { if (!class_exists('Timber')) { throw new \RuntimeException("Timber is not installed"); } \Timber::render($template, $context); }
public static function setup($output, $attr) { global $post; $html5 = current_theme_supports('html5'); $atts = shortcode_atts(array('order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post ? $post->ID : 0, 'itemtag' => $html5 ? 'figure' : 'dl', 'icontag' => $html5 ? 'div' : 'dt', 'captiontag' => $html5 ? 'figcaption' : 'dd', 'columns' => 3, 'size' => 'thumbnail', 'include' => '', 'exclude' => '', 'link' => ''), $attr, 'gallery'); $id = intval($atts['id']); if (!empty($atts['include'])) { $posts = get_posts(array('include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'])); $attachments = array(); foreach ($posts as $key => $val) { $attachments[$val->ID] = $posts[$key]; } } elseif (!empty($atts['exclude'])) { $attachments = get_children(array('post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'])); } else { $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'])); } if (count($attachments)) { foreach ($attachments as &$attachment) { $attachment = new \TimberImage($attachment); } // add a static incrementer for the gallery HTML ID to allow more than one per page. static $gallery_inc = 0; $gallery_inc++; $data['id'] = sprintf("gallery-%s", $gallery_inc); $data['thumbnails'] = $attachments; return \Timber::compile('gallery.twig', $data); } }
/** * button * * Displays the addthis sharing button setup on their dashboard page */ public static function button() { if ($addthis_id = get_theme_mod('addthis-id')) { wp_enqueue_script('addthis'); \Timber::render('addthis.twig'); } }
function testTermToString() { $term_id = $this->factory->term->create(array('name' => 'New England Patriots')); $term = new TimberTerm('new-england-patriots'); $str = Timber::compile_string('{{term}}', array('term' => $term)); $this->assertEquals('New England Patriots', $str); }
function testCommentCountZero() { $quote = 'Named must your fear be before banish it you can.'; $post_id = $this->factory->post->create(array('post_content' => $quote)); $post = Timber::get_post($post_id); $this->assertEquals(0, $post->get_comment_count()); }
/** * get_post * * @return mixed */ protected function get_post() { if (empty($this->post)) { $this->post = \Timber::get_post(); } return $this->post; }
public function __construct($path, $name = '') { parent::__construct($path, $name); $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; \Timber::$locations = $locator->findResources('gantry-engine://views'); add_theme_support('html5', ['comment-list', 'comment-form', 'search-form', 'gallery', 'caption', 'widgets']); add_theme_support('title-tag'); add_theme_support('post-formats'); add_theme_support('post-thumbnails'); add_theme_support('menus'); add_theme_support('widgets'); add_filter('timber_context', [$this, 'add_to_context']); add_filter('get_twig', [$this, 'add_to_twig']); add_action('template_redirect', [$this, 'set_template_layout'], -10000); add_action('init', [$this, 'register_post_types']); add_action('init', [$this, 'register_taxonomies']); add_action('widgets_init', [$this, 'widgets_init']); add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts']); add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']); add_action('wp_head', [$this, 'print_styles'], 20); add_action('wp_head', [$this, 'print_scripts'], 30); add_action('admin_print_styles', [$this, 'print_styles'], 200); add_action('admin_print_scripts', [$this, 'print_scripts'], 200); add_action('wp_footer', [$this, 'print_inline_scripts']); }
/** * render * * Render cookie-consent.twig * */ public function render() { if (!isset($_COOKIE['cookie-consent'])) { do_action('show_cookie_consent'); \Timber::render('cookie-consent.twig', array('implied_consent_text' => get_theme_mod('implied-consent-text', $this->implied_consent_text), 'button_text' => get_theme_mod('button-text', $this->button_text), 'privacy_url' => get_theme_mod('privacy-url', $this->privacy_url), 'privacy_link_text' => get_theme_mod('privacy-link-text', $this->privacy_link_text))); } }
function render_product_popup() { $intPostId = intval($_POST['post_id']); $objPost = new TimberPost($intPostId); Timber::render('partials/product-popup.twig', array('post' => $objPost)); wp_die(); }
static function get_projects() { if (self::is_client()) { return array(); } return Timber::get_posts(array('orderby' => 'title', 'post_type' => 'project', 'order' => 'ASC')); }
function testTwigFilterDateWordPressOption() { $format = get_option('date_format'); $str = Timber::compile_string("{{now|date('" . $format . "')}}"); $empty = Timber::compile_string("{{now|date}}"); $this->assertSame($str, $empty); }
/** * add_to_context * * Add available widgets to the Timber context * * @param $context * * @return array */ public static function add_to_context($context) { foreach (static::$widgets as $key => &$widget) { $context["widget_{$key}"] = \Timber::get_widgets($widget['id']); } return $context; }
function get_my_gallery_content($atts) { foreach (explode(',', $atts['ids']) as $id) { $context["feed"][] = array('medium' => wp_get_attachment_image_src($id, 'Medium'), 'full' => wp_get_attachment_image_src($id, 'Full')); } $context["slide_template"] = 'views/content/post_gallery_img.twig'; return Timber::compile('view/component/post_gallery.twig', $context); }
function add_to_context($context) { $context['site'] = $this; $context['nav_bar'] = new TimberMenu('main-nav-bar'); $context['nav_widgets'] = Timber::get_widgets('site_nav_widgets'); $context['sidebar'] = Timber::get_widgets('site_sidebar'); return $context; }
function testLinkOnSubdirectoryInstall() { update_option('siteurl', 'http://example.org/wordpress', true); $context = Timber::get_context(); $theme = $context['site']->theme; $output = Timber::compile_string('{{site.theme.link}}', $context); $this->assertEquals('http://example.org/wp-content/themes/' . $theme->slug, $output); }
function testShortcodes() { add_shortcode('timber_shortcode', function ($text) { return 'timber ' . $text[0]; }); $return = Timber::compile('assets/test-shortcodes.twig'); $this->assertEquals('hello timber foo', trim($return)); }
function testGetData() { $_GET['foo'] = 'bar'; $template = '{{request.get.foo}}'; $context = Timber::get_context(); $str = Timber::compile_string($template, $context); $this->assertEquals('bar', $str); }
function sugestao($params) { $query = 'category_name=' . $params['name'] . '&aba=' . $params['aba']; // if ($params['aba'] == 'geral') // Timber::load_template('passo-3-geral.php', $query); // else Timber::load_template('passo-3.php', $query); }
function testCallingPHPFile() { $phpunit = $this; add_filter('timber/calling_php_file', function ($file) use($phpunit) { $phpunit->assertStringEndsWith('/timber/tests/test-timber-debug.php', $file); }); Timber::compile('assets/output.twig'); }
function testTypeMethodInTwigLabels() { $post_id = $this->factory->post->create(); $post = new TimberPost($post_id); $template = '{{post.type.labels.name}}'; $str = Timber::compile_string($template, array('post' => $post)); $this->assertEquals('Posts', $str); }
function testPreviewWithSpaceInMoreTag() { $pid = $this->factory->post->create(array('post_content' => 'Lauren is a duck, but a great duck let me tell you why <!--more--> Lauren is not a duck', 'post_excerpt' => '')); $post = new TimberPost($pid); $template = '{{post.preview.length(3).force}}'; $str = Timber::compile_string($template, array('post' => $post)); $this->assertEquals('Lauren is a… <a href="' . $post->link() . '" class="read-more">Read More</a>', $str); }
/** * 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; }
function testImageResizeRetinaFilterNotAnImage() { self::enable_error_log(false); $str = 'Image? {{"/wp-content/uploads/2016/07/stuff.jpg"|retina(3)}}'; $compiled = Timber::compile_string($str); $this->assertEquals('Image? /wp-content/uploads/2016/07/stuff.jpg', $compiled); self::enable_error_log(true); }