本文整理汇总了PHP中Timber::get_posts方法的典型用法代码示例。如果您正苦于以下问题:PHP Timber::get_posts方法的具体用法?PHP Timber::get_posts怎么用?PHP Timber::get_posts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timber
的用法示例。
在下文中一共展示了Timber::get_posts方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_projects
static function get_projects()
{
if (self::is_client()) {
return array();
}
return Timber::get_posts(array('orderby' => 'title', 'post_type' => 'project', 'order' => 'ASC'));
}
示例2: get_posts
/**
* get_posts
*
* @return mixed
*/
protected function get_posts()
{
if (empty($this->posts)) {
$this->posts = \Timber::get_posts();
}
return $this->posts;
}
示例3: 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;
}
示例4: 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;
}
示例5: load_view
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);
}
示例6: get_posts
/**
* 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;
}
示例7: get_sorted_projects
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;
}
示例8: testGetPostsArrayCount
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));
}
示例9: testimonials
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;
}
示例10: add_to_context
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;
}
示例11: widget
/**
* 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();
}
示例12: widget
/**
* 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();
}
示例13: widget
/**
* 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();
}
示例14: 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;
}
示例15: getRoll
/** 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);
}