当前位置: 首页>>代码示例>>PHP>>正文


PHP Timber类代码示例

本文整理汇总了PHP中Timber的典型用法代码示例。如果您正苦于以下问题:PHP Timber类的具体用法?PHP Timber怎么用?PHP Timber使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Timber类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: in_news_int

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;
}
开发者ID:Gregcop1,项目名称:wp-dummy-twig,代码行数:32,代码来源:shortcode.php

示例2: testGetWithQueryString

 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);
 }
开发者ID:Butterwell,项目名称:timber,代码行数:33,代码来源:test-timber-term-getter.php

示例3: context

 /**
  * 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;
 }
开发者ID:wpmu,项目名称:maera,代码行数:34,代码来源:class-maera-template.php

示例4: add_to_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;
 }
开发者ID:benedict-w,项目名称:pressgang,代码行数:16,代码来源:sidebars.php

示例5: form

 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);
 }
开发者ID:emilyhorsman,项目名称:timber-test-widget,代码行数:7,代码来源:timber-test-widget.class.php

示例6: load_view

 public function load_view()
 {
     $context = Timber::get_context();
     $context['data'] = $this->data;
     $context['constants'] = get_slate_constants();
     Timber::render(theme_views . '/single.twig', $context);
 }
开发者ID:bmc75,项目名称:wpmvc,代码行数:7,代码来源:single-service.php

示例7: add_to_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;
}
开发者ID:jamesaveryw,项目名称:mississippi-staging,代码行数:28,代码来源:functions.php

示例8: render

 /**
  * 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);
 }
开发者ID:Ye-Yong-Chi,项目名称:beautyUniversity,代码行数:15,代码来源:AbstractTimberController.php

示例9: setup

 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);
     }
 }
开发者ID:benedict-w,项目名称:pressgang,代码行数:29,代码来源:gallery.php

示例10: button

 /**
  * 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');
     }
 }
开发者ID:AliBritt,项目名称:pressgang,代码行数:12,代码来源:addthis.php

示例11: testTermToString

 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);
 }
开发者ID:mrgrain,项目名称:timber,代码行数:7,代码来源:test-timber-term.php

示例12: testCommentCountZero

 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());
 }
开发者ID:gwafork,项目名称:timber,代码行数:7,代码来源:test-timber-post-comments.php

示例13: get_post

 /**
  * get_post
  *
  * @return mixed
  */
 protected function get_post()
 {
     if (empty($this->post)) {
         $this->post = \Timber::get_post();
     }
     return $this->post;
 }
开发者ID:benedict-w,项目名称:pressgang,代码行数:12,代码来源:page-controller.php

示例14: __construct

 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']);
 }
开发者ID:austbot,项目名称:gantry5-composer,代码行数:27,代码来源:Theme.php

示例15: render

 /**
  * 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)));
     }
 }
开发者ID:benedict-w,项目名称:pressgang,代码行数:13,代码来源:cookie-consent.php


注:本文中的Timber类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。