本文整理汇总了PHP中Timber::get_terms方法的典型用法代码示例。如果您正苦于以下问题:PHP Timber::get_terms方法的具体用法?PHP Timber::get_terms怎么用?PHP Timber::get_terms使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timber
的用法示例。
在下文中一共展示了Timber::get_terms方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_context
/**
* Custom implementation for get_context method.
*/
public function get_context()
{
global $content_width;
if (class_exists('Easy_Digital_Downloads')) {
global $edd_options;
}
$context = Timber::get_context();
$sidebar_primary = Timber::get_widgets('sidebar_primary');
$sidebar_footer = Timber::get_widgets('sidebar_footer');
$context['theme_mods'] = get_theme_mods();
$context['site_options'] = wp_load_alloptions();
$context['teaser_mode'] = apply_filters('maera/teaser/mode', 'excerpt');
$context['thumbnail']['width'] = apply_filters('maera/image/width', 600);
$context['thumbnail']['height'] = apply_filters('maera/image/height', 371);
$context['menu']['primary'] = has_nav_menu('primary_navigation') ? new TimberMenu('primary_navigation') : null;
$context['sidebar']['primary'] = apply_filters('maera/sidebar/primary', $sidebar_primary);
$context['sidebar']['footer'] = apply_filters('maera/sidebar/footer', $sidebar_footer);
$context['pagination'] = Timber::get_pagination();
$context['comment_form'] = TimberHelper::get_comment_form();
$context['comments_args'] = array('style' => 'ul', 'reply_text' => __('Reply', 'maera'), 'short_ping' => true, 'avatar_size' => 60);
$context['site_logo'] = get_option('site_logo', false);
$context['content_width'] = $content_width;
$context['sidebar_template'] = maera_templates_sidebar();
if (class_exists('Easy_Digital_Downloads')) {
$data['edd_options'] = $edd_options;
$data['download_categories'] = Timber::get_terms('download_category');
$data['download_tags'] = Timber::get_terms('download_tag');
$data['default_image'] = new TimberImage(get_template_directory_uri() . '/assets/images/default.png');
}
return apply_filters('maera/timber/context', $context);
}
示例2: create_sitemap
/**
* Function to create sitemap.xml file in root directory
*
*/
public function create_sitemap($post_id, $post, $update)
{
// only create a site map if the post is new or no file exists
if (wp_is_post_revision($post_id) || is_file($this->path())) {
// return false;
}
$post_types = get_post_types(array('public' => true, 'publicly_queryable' => true));
$nodes = array();
$posts = \Timber::get_posts(array('numberposts' => -1, 'orderby' => array('type', 'modified'), 'post_type' => $post_types, 'order' => 'DESC', 'post_status' => 'publish'));
foreach ($posts as &$post) {
$nodes[] = array('loc' => $post->link, 'lastmod' => get_post_modified_time('c', false, $post), 'changefreq' => $this->get_post_change_frequency($post), 'priority' => $this->get_priority($post));
}
$taxonomies = get_taxonomies(array('public' => true, 'publicly_queryable' => true));
$terms = \Timber::get_terms(array('taxonomy' => $taxonomies, 'hide_empty' => false));
foreach ($terms as &$term) {
$lastest_post = $term->get_post(array('numberposts' => 1));
$nodes[] = array('loc' => get_term_link($term), 'lastmod' => get_post_modified_time('c', false, $lastest_post), 'changefreq' => $this->change_frequency, 'priority' => $this->get_priority($term));
}
$data = array('nodes' => $nodes);
$sitemap = \Timber::compile('sitemap-xml.twig', $data);
$path = $this->path();
if ($fp = fopen($path, 'w')) {
fwrite($fp, $sitemap);
fclose($fp);
}
}
示例3: 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);
}
示例4: testSubclass
function testSubclass()
{
$term_ids = array();
$class_name = 'TimberTermSubclass';
require_once 'php/timber-term-subclass.php';
$term_ids[] = $this->factory->term->create();
$term_ids[] = $this->factory->term->create();
$term_ids[] = $this->factory->term->create();
$term_ids[] = $this->factory->term->create();
$terms = Timber::get_terms($term_ids, $class_name);
$this->assertEquals($class_name, get_class($terms[0]));
$terms = false;
$terms = Timber::get_terms($term_ids, null, $class_name);
$this->assertEquals($class_name, get_class($terms[0]));
$terms = false;
$terms = Timber::get_terms($term_ids, array(), $class_name);
$this->assertEquals($class_name, get_class($terms[0]));
}
示例5: maera_res_context
/**
* 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;
}
示例6: get_query_var
<?php
global $s;
$page = get_query_var('paged');
if ($page && $page >= 2) {
// If we're on a pagination page, we'll add a "Page [page]" to the title, so
// that SEO services don't complain about duplicate titles
add_filter('wpseo_title', function ($title) use($page) {
return $title . " | Page {$page}";
});
}
Timber::render('templates/blog/search-results.twig', array_merge(Timber::get_context(), array('pagination' => Timber::get_pagination(), 'searchTerm' => $s, 'categories' => Timber::get_terms('category'), 'tags' => Timber::get_terms('tag'), 'results' => Timber::get_posts(array('post_type' => 'post', 's' => $s)))));
示例7: TimberPost
<?php
/*
* Template Name: Issues Archive
*/
$data = Timber::get_context();
$post = new TimberPost();
$issues = Timber::get_terms('issue');
$data['issues'] = $issues;
$data['post'] = $post;
Timber::render('issue-archive.twig', $data);
示例8: array_merge
<?php
$context = Timber::get_context();
$context = array_merge($context, array('categories' => Timber::get_terms('category'), 'tags' => Timber::get_terms('tag'), 'post_prev' => $context['post']->prev(), 'post_next' => $context['post']->next(), 'relatedPosts' => $context['post']->getRelated(3)));
Timber::render('templates/blog/post.twig', $context);
示例9: TimberPost
//Template initialization
$post = new TimberPost();
$context_holder['post'] = $post;
$parent_data = get_page_parent_title($post);
$context_holder['sidebar_elements'] = array('static/suggeriment.twig', 'baixades.twig', 'links.twig');
$context_holder['links'] = $post->get_field('link');
$context_holder['credits'] = $post->get_field('credit');
$context_holder['parent_title'] = $parent_data['title'];
$context_holder['page_hierarchy'] = wp_list_subpages($parent_data['id']);
//Stats data
$json_path = ABSPATH . "../aparells.json";
$context_holder['stats_aparells'] = json_decode(file_get_contents($json_path));
//Filters population
$context_holder['categories']['sistemesoperatius'] = Timber::get_terms('so_aparell');
$context_holder['categories']['tipus'] = Timber::get_terms('tipus_aparell');
$context_holder['categories']['fabricants'] = Timber::get_terms('fabricant');
//Search and filters
$search = get_query_var('cerca');
$sistema_operatiu = get_query_var('sistema_operatiu');
$tipus_aparell = get_query_var('tipus_aparell');
$fabricant = get_query_var('fabricant');
//Generate $args query
if (!empty($search) || !empty($sistema_operatiu) || !empty($tipus_aparell) || !empty($fabricant)) {
$query_aparell['s'] = $search;
$query_aparell['so_aparell'] = $sistema_operatiu;
$query_aparell['tipus_aparell'] = $tipus_aparell;
$query_aparell['fabricant'] = $fabricant;
$args = get_post_query_args('aparell', SearchQueryType::Aparell, $query_aparell);
$title = 'Aparells - ';
!empty($search) ? $title .= 'cerca: ' . $search . ' - ' : '';
!empty($tipus_aparell) ? $title .= 'tipus: ' . get_term_name_by_slug($tipus_aparell, 'tipus_aparell') . ' - ' : '';
示例10: get_field
$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);
示例11: get_query_var
<?php
$page = get_query_var('paged');
if ($page && $page >= 2) {
// If we're on a pagination page, we'll add a "Page [page]" to the title, so
// that SEO services don't complain about duplicate titles
add_filter('wpseo_title', function ($title) use($page) {
return $title . " | Page {$page}";
});
}
Timber::render('templates/blog.twig', array_merge(Timber::get_context(), array('page' => new TimberPost('blog'), 'categories' => Timber::get_terms('category'), 'tags' => Timber::get_terms('tag'), 'pagination' => Timber::get_pagination())));
示例12: TimberPost
<?php
/**
* Template Name: Reason Categories
*
* Description: An archive listing a few posts from each term in the Recipes Type taxonomy
*
*/
$context = Timber::get_context();
$post = new TimberPost();
$context['post'] = $post;
// Get the terms from the recipe_type post
$context['types'] = Timber::get_terms('reason_type');
Timber::render(array('page-reasoncategories.twig', 'page.twig'), $context);
示例13: get_option
$data['base'] = 'base-blank.twig';
}
$data['wp_title'] = 'Upstatement - Blog';
$page = 0;
if ($wp_query->query['offset']) {
$page = $wp_query->query['offset'] / 6 + 1;
}
$data['blog_cron'] = Timber::get_posts();
$sticky = get_option('sticky_posts');
$sticky = TimberHelper::array_truncate($sticky, 4);
if ($page == 0) {
$featured_query = array('post_type' => 'post', 'numberposts' => 4, 'post__in' => $sticky);
$data['blog_featured'] = Timber::get_posts($featured_query);
}
$next_query = array('post_type' => 'post', 'numberposts' => 1, 'post__not_in' => $sticky, 'offset' => ($page + 1) * 6);
$data['blog_next'] = Timber::get_posts($next_query);
$data['tags'] = Timber::get_terms('tax=tags&orderby=count&number=20');
shuffle($data['tags']);
$data['tags'] = TimberHelper::array_truncate($data['tags'], 10);
$next_page = $page + 1;
if ($page == 0) {
$next_page = 2;
}
if (count($data['blog_next'])) {
$data['next_button_url'] = '/blog/page/' . $next_page;
}
if ($api) {
Timber::render('mods/archive-blog-loop.twig', $data);
} else {
Timber::render('archive-blog.twig', $data);
}
示例14: TimberPost
<?php
/**
* Template Name: Food Categories
*
* Description: An archive listing a few posts from each term in the Recipes Type taxonomy
*
*/
$context = Timber::get_context();
$post = new TimberPost();
$context['post'] = $post;
// Get the terms from the recipe_type post
$context['types'] = Timber::get_terms('food_type');
Timber::render(array('page-foodcategories.twig', 'page.twig'), $context);
示例15: TimberPost
<?php
/*
Template Name: Products
*/
$context = Timber::get_context();
$post = new TimberPost();
$context['post'] = $post;
$categories = Timber::get_terms('product-categories', array('parent' => 0));
$context['categories'] = $categories;
Timber::render(array('page-products.twig', 'page.twig'), $context);