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


PHP Timber::compile方法代码示例

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


在下文中一共展示了Timber::compile方法的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: 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

示例3: get_my_gallery_content

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);
}
开发者ID:bcbroussard,项目名称:POST,代码行数:8,代码来源:functions.php

示例4: testShortcodes

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

示例5: testCallingPHPFile

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

示例6: testInTwig

 function testInTwig()
 {
     global $wp_scripts;
     $wp_scripts = null;
     wp_enqueue_script('jquery', false, array(), false, true);
     $str = Timber::compile('assets/wp-footer.twig', array());
     $this->stringContains('http://example.org/wordpress/wp-includes/js/jquery/jquery.js', $str);
 }
开发者ID:Butterwell,项目名称:timber,代码行数:8,代码来源:test-timber-wp-functions.php

示例7: IgnoretestBasicCollectionWithPaginationAndBlankQuery

 function IgnoretestBasicCollectionWithPaginationAndBlankQuery()
 {
     $pids = $this->factory->post->create_many(130);
     $this->go_to('/');
     $pc = new Timber\PostQuery();
     $str = Timber::compile('assets/collection-pagination.twig', array('posts' => $pc));
     $str = preg_replace('/\\s+/', ' ', $str);
     $this->assertEquals('<h1>POST</h1> <h1>POST</h1> <h1>POST</h1> <h1>POST</h1> <h1>POST</h1> <h1>POST</h1> <h1>POST</h1> <h1>POST</h1> <h1>POST</h1> <h1>POST</h1> <div class="l--pagination"> <div class="pagination-inner"> <div class="pagination-previous"> <span class="pagination-previous-link pagination-disabled">Previous</span> </div> <div class="pagination-pages"> <ul class="pagination-pages-list"> <li class="pagination-list-item pagination-page">1</li> <li class="pagination-list-item pagination-seperator">of</li> <li class="pagination-list-item pagination-page">13</li> </ul> </div> <div class="pagination-next"> <a href="http://example.org/?paged=2" class="pagination-next-link ">Next</a> </div> </div> </div>', trim($str));
 }
开发者ID:jarednova,项目名称:timber,代码行数:9,代码来源:test-timber-post-collection.php

示例8: testTwigSidebar

 function testTwigSidebar()
 {
     $context = Timber::get_context();
     $sidebar_post = $this->factory->post->create(array('post_title' => 'Sidebar post content'));
     $sidebar_context = array();
     $sidebar_context['post'] = new TimberPost($sidebar_post);
     $context['sidebar'] = Timber::get_sidebar('assets/sidebar.twig', $sidebar_context);
     $result = Timber::compile('assets/main-w-sidebar.twig', $context);
     $this->assertEquals('I am the main stuff <h4>Sidebar post content</h4>', trim($result));
 }
开发者ID:alexaldama,项目名称:timber,代码行数:10,代码来源:test-timber-sidebar.php

示例9: testPHPSidebar

 function testPHPSidebar()
 {
     add_filter('timber_context', function ($context) {
         $context['sidebar'] = Timber::get_sidebar('assets/my-sidebar.php');
         return $context;
     });
     $context = Timber::get_context();
     $result = Timber::compile('assets/main-w-sidebar-php.twig', $context);
     $this->assertEquals("A Fever You Can't Sweat Out by Panic! at the Disco from 2005", trim($result));
 }
开发者ID:aauroux,项目名称:timber,代码行数:10,代码来源:test-timber-sidebar.php

示例10: testTheLoop

 function testTheLoop()
 {
     for ($i = 1; $i < 3; $i++) {
         $this->factory->post->create(array('post_title' => 'TestPost' . $i));
     }
     $results = Timber::compile('assets/iterator-test.twig', array('posts' => TimberPostGetter::query_posts('post_type=post')));
     $results = trim($results);
     $this->assertStringStartsWith('TestPost2', $results);
     $this->assertStringEndsWith('TestPost1', $results);
 }
开发者ID:rjagadishsingh,项目名称:timber,代码行数:10,代码来源:test-timber-iterator.php

示例11: paypal_item_shortcode

 /**
  * paypal_item_shortcode
  *
  */
 public function paypal_item_shortcode($atts)
 {
     $atts = shortcode_atts(array('id' => null), $atts);
     if ($atts['id']) {
         $item = \Timber::get_post($atts['id']);
         if ($item->post_type === 'paypal_item') {
             $account = array('email' => get_field('paypal_email', 'option'), 'currency' => get_field('paypal_currency', 'option'), 'location' => get_field('paypal_location', 'option'));
             return \Timber::compile('paypal-item.twig', array('paypal_item' => $item, 'paypal_account' => $account));
         }
     }
 }
开发者ID:benedict-w,项目名称:pressgang,代码行数:15,代码来源:paypal.php

示例12: testMenuTwigWithClasses

 function testMenuTwigWithClasses()
 {
     $this->setPermalinkStructure();
     $this->_createTestMenu();
     $this->go_to(home_url('/home'));
     $context = Timber::get_context();
     $context['menu'] = new TimberMenu();
     $str = Timber::compile('assets/menu-classes.twig', $context);
     $str = trim($str);
     $this->assertContains('current_page_item', $str);
     $this->assertContains('current-menu-item', $str);
     $this->assertContains('menu-item-object-page', $str);
     $this->assertNotContains('foobar', $str);
 }
开发者ID:hamedb89,项目名称:wp-theme-boilerplate,代码行数:14,代码来源:test-timber-menu.php

示例13: testParentChildGeneral

 function testParentChildGeneral()
 {
     TestTimberLoader::_setupParentTheme();
     TestTimberLoader::_setupChildTheme();
     switch_theme('fake-child-theme');
     register_post_type('course');
     //copy a specific file to the PARENT directory
     $dest_dir = WP_CONTENT_DIR . '/themes/twentythirteen';
     copy(__DIR__ . '/assets/single-course.twig', $dest_dir . '/views/single-course.twig');
     $pid = $this->factory->post->create();
     $post = new TimberPost($pid);
     $str = Timber::compile(array('single-course.twig', 'single.twig'), array('post' => $post));
     $this->assertEquals('I am single course', $str);
 }
开发者ID:Butterwell,项目名称:timber,代码行数:14,代码来源:test-timber-parent-child.php

示例14: testWordPressPasswordFilters

 function testWordPressPasswordFilters()
 {
     $post_id = $this->factory->post->create(array('post_title' => 'My Private Post', 'post_password' => 'abc123'));
     $context = array();
     add_filter('protected_title_format', function ($title) {
         return 'Protected: ' . $title;
     });
     $context['post'] = new TimberPost($post_id);
     if (post_password_required($post_id)) {
         $this->assertTrue(true);
         $str = Timber::compile('assets/test-wp-filters.twig', $context);
         $this->assertEquals('Protected: My Private Post', trim($str));
     } else {
         $this->assertTrue(false, 'Something wrong with the post password reqd');
     }
 }
开发者ID:aauroux,项目名称:timber,代码行数:16,代码来源:test-timber-twig.php

示例15: do_shortcode

 /**
  * do_shortcode
  *
  * Render the shortcode template
  *
  * @return string
  */
 public function do_shortcode($atts, $content = null)
 {
     $args = shortcode_atts($this->get_defaults(), $atts);
     wp_register_script('pressgang-google-map', get_template_directory_uri() . '/js/src/custom/google-map.js');
     wp_enqueue_script('pressgang-google-map');
     // TODO defer - http://matthewhorne.me/defer-async-wordpress-scripts/
     wp_register_script('google-maps', sprintf('https://maps.googleapis.com/maps/api/js?key=%s&callback=initMap', $args['api']), array('jquery', 'pressgang-google-map'));
     wp_enqueue_script('google-maps');
     \Pressgang\Scripts::$defer[] = 'google-maps';
     \Pressgang\Scripts::$async[] = 'google-maps';
     \Pressgang\Scripts::$async[] = 'pressgang-google-map';
     static $i;
     $i++;
     $args['id'] = sprintf("google-maps-%d", $i);
     $this->context = $args;
     return \Timber::compile($this->template, $this->context);
 }
开发者ID:benedict-w,项目名称:pressgang,代码行数:24,代码来源:google-map.php


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