/** * 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); }
function add_to_context($context) { $context['current_url'] = TimberHelper::get_current_url(); $context['pagination'] = Timber::get_pagination(); $context['bethel_header_menu'] = new TimberMenu('primary'); $context['bethel_sidebar_menu'] = new TimberMenu('sidebar'); $context['site'] = $this; return $context; }
/** * {@inheritdoc} */ public function getContext() { $data = []; $data['posts'] = $this->getPosts(); $data['title'] = __('Archive', 'zero'); if (is_day()) { $data['title'] = __('Archive: ', 'zero') . get_the_date('D M Y'); } elseif (is_month()) { $data['title'] = __('Archive: ', 'zero') . get_the_date('M Y'); } elseif (is_year()) { $data['title'] = __('Archive: ', 'zero') . get_the_date('Y'); } elseif (is_tag()) { $data['title'] = single_tag_title('', false); } elseif (is_category()) { $data['title'] = single_cat_title('', false); } elseif (is_post_type_archive()) { $data['title'] = post_type_archive_title('', false); } $data['pagination'] = \Timber::get_pagination(); return $data; }
$search_args = get_post_query_args('esdeveniment', SearchQueryType::Search, $search); $args = wp_parse_args($search_args, $wp_query->query); //search + active args $date_filter_args = get_post_query_args('esdeveniment', SearchQueryType::FilteredDate, $filterdate); $args = wp_parse_args($date_filter_args, $args); //all filters applied $date_filter_args = get_post_query_args('esdeveniment', SearchQueryType::FilteredTema, $tema); $args = wp_parse_args($date_filter_args, $args); //all filters applied $context_holder['selected_filter_tema'] = $tema; $context_holder['selected_filter_data'] = $filter; $context_holder['cerca'] = $search; $title = 'Esdeveniments - '; !empty($search) ? $title .= 'cerca: ' . $search . ' - ' : ''; !empty($tema) ? $title .= 'tema: ' . get_term_name_by_slug($tema, 'esdeveniment_cat') . ' - ' : ''; !empty($filter) ? $title .= 'data: ' . get_the_filter_date_name($filter) . ' - ' : ''; $title .= 'Softcatalà'; } else { $title = 'Esdeveniments - Softcatalà'; $description = 'Esdeveniments relacionats amb el món de la tecnologia i el català.'; $args = $wp_query->query; } //Posts and pagination query_posts($args); $context_holder['posts'] = Timber::get_posts($args); $context_holder['pagination'] = Timber::get_pagination(); //Context initialization $context_filterer = new SC_ContextFilterer($context_holder); $context_overrides = array('title' => $title, 'description' => $description); $context = $context_filterer->get_filtered_context($context_overrides, false); Timber::render($templates, $context);
/** * Extend the Timber context * * @param array $context * * @return array */ public static function add_to_context(array $context) { $context['is_user_logged_in'] = is_user_logged_in(); $context['pagination'] = Timber::get_pagination(); return $context; }
function testPaginationInCategory($struc = '/%postname%/') { global $wp_rewrite; $wp_rewrite->permalink_structure = $struc; update_option('permalink_structure', $struc); $no_posts = $this->factory->post->create_many(25); $posts = $this->factory->post->create_many(31); $news_id = wp_insert_term('News', 'category'); foreach ($posts as $post) { wp_set_object_terms($post, $news_id, 'category'); } $this->go_to(home_url('/category/news')); $post_objects = Timber::get_posts(false); $pagination = Timber::get_pagination(); //need to complete test }
/** * The main template file * This is the most generic template file in a WordPress theme * and one of the two required files for a theme (the other being style.css). * It is used to display a page when nothing more specific matches a query. * E.g., it puts together the home page when no home.php file exists * * Methods for TimberHelper can be found in the /functions sub-directory * * @package WordPress * @subpackage Underwood * @since Underwood 0.0.1 */ if (!class_exists('Timber')) { echo 'Timber not activated. Make sure you activate the plugin in <a href="/wp-admin/plugins.php#timber">/wp-admin/plugins.php</a>'; return; } //$context = array(); $context = Timber::get_context(); $context['posts'] = Timber::get_posts(); $context['pagination'] = Timber::get_pagination(); /* Dynamic Sidebar */ $context['sidebar'] = Timber::get_widgets('Sidebar'); // $sidebar_context = array(); // $sidebar_context['related'] = Timber::get_posts('cat='.$post_cat); // $context['sidebar'] = Timber::get_sidebar('sidebar-related.twig', $sidebar_context); $templates = array('index.twig'); if (is_home()) { array_unshift($templates, 'home.twig'); } Timber::render($templates, $context);
<?php // prepare data $data = Timber::get_context(); $data['posts'] = Timber::get_posts(); $data['pagination'] = Timber::get_pagination(); $data['date_format'] = get_option('date_format'); $data['time_format'] = get_option('time_format'); // prepare template array $templates = array(); if (is_tax()) { $data['term'] = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); $templates[] = 'listing/list-taxonomy-' . $data['term']->taxonomy . '.html.twig'; $templates[] = 'listing/list-taxonomy.html.twig'; } elseif (is_category()) { $data['category'] = get_category(get_query_var('cat')); $templates[] = 'listing/list-category-' . $data['category']->slug . '.html.twig'; $templates[] = 'listing/list-category.html.twig'; } elseif (is_tag()) { $data['tag'] = get_queried_object(); $templates[] = 'listing/list-tag-' . $data['tag']->name . '.html.twig'; $templates[] = 'listing/list-tag.html.twig'; } elseif (is_author()) { $data['author'] = get_queried_object(); $templates[] = 'listing/list-author-' . $data['author']->user_nicename . '.html.twig'; $templates[] = 'listing/list-author.html.twig'; } elseif (is_date()) { if (is_year()) { $data['date'] = get_the_time('Y'); } else { $data['date'] = get_the_time('F Y');
function testPaginationPrevUsesBaseAndFormatArgs($struc = '/%postname%/') { global $wp_rewrite; $wp_rewrite->permalink_structure = $struc; update_option('permalink_structure', $struc); $posts = $this->factory->post->create_many(55); $this->go_to(home_url('/apricot/page=3')); query_posts('paged=3'); $GLOBALS['paged'] = 3; $pagination = Timber::get_pagination(array('base' => '/apricot/%_%', 'format' => 'page=%#%')); $this->assertEquals('/apricot/page=2', $pagination['prev']['link']); }
<?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)))));
/** * get_pagination * * @return mixed */ protected function get_pagination() { if (empty($this->pagination)) { $this->pagination = \Timber::get_pagination(); } return $this->pagination; }
public function add_to_context($context) { $context['regions'] = $this->get_theme_regions(); $context['menu'] = new TimberMenu(); $context['site'] = $this; $context['pagination'] = Timber::get_pagination(); $context['comment_form'] = TimberHelper::get_comment_form(); return $context; }
<?php $context = Timber::get_context(); $context['posts'] = Timber::get_posts(); if (is_archive()) { $context['title'] = get_the_archive_title(); } else { $context['title'] = get_the_title(get_option('page_for_posts')); } $context['description'] = get_the_archive_description('<div class="archive-description">', '</div>'); $context['pagination'] = Timber::get_pagination(array('mid_size' => 2)); Timber::render('index.twig', $context);
<?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())));
function testPaginationWithMoreThan10Pages($struc = '/%postname%/') { global $wp_rewrite; $wp_rewrite->permalink_structure = $struc; update_option('permalink_structure', $struc); $posts = $this->factory->post->create_many(150); $this->go_to(home_url('/page/13')); $pagination = Timber::get_pagination(); $expected_next_link = user_trailingslashit('http://example.org/page/14/'); $this->assertEquals($expected_next_link, $pagination['next']['link']); }
<?php // prepare data $data = Timber::get_context(); $data['posts'] = Timber::get_posts(); $data['pagination'] = $data['posts'] ? Timber::get_pagination() : null; // wordpress pagination seems broken for empty search results $data['date_format'] = get_option('date_format'); $data['time_format'] = get_option('time_format'); // render template Timber::render(array('pages/search.html.twig', 'content/list.html.twig'), $data);