Esempio n. 1
0
 function testAmpersandInTitle()
 {
     $post_id = $this->factory->post->create(array('post_title' => 'Jared & Lauren'));
     $post = new TimberPost($post_id);
     $this->assertEquals(get_the_title($post_id), $post->title());
     $this->assertEquals(get_the_title($post_id), $post->post_title);
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * add meta_description
  *
  * hook after post has loaded to add a unique meta-description
  *
  */
 public static function meta_description()
 {
     $post = new \TimberPost();
     // check for custom field
     $description = wptexturize($post->get_field('meta_description'));
     if (is_tax()) {
         if ($temp = term_description(get_queried_object(), get_query_var('taxonomy'))) {
             $description = $temp;
         }
     } elseif (is_post_type_archive()) {
         if ($temp = get_the_archive_description()) {
             $description = $temp;
         }
     }
     // else use preview
     if (empty($description)) {
         $description = str_replace('', "'", $post->get_preview(40, true, false, true));
     }
     // finally use the blog description
     if (empty($description)) {
         $description = get_bloginfo('description', 'raw');
     }
     $description = esc_attr(wp_strip_all_tags($description));
     // limit to SEO recommended length
     if (strlen($description) > 155) {
         $description = substr($description, 0, 155);
         $description = \TimberHelper::trim_words($description, str_word_count($description) - 1);
     }
     return $description;
 }
 function testPreviewWithSpaceInMoreTag()
 {
     $pid = $this->factory->post->create(array('post_content' => 'Lauren is a duck, but a great duck let me tell you why <!--more--> Lauren is not a duck', 'post_excerpt' => ''));
     $post = new TimberPost($pid);
     $template = '{{post.preview.length(3).force}}';
     $str = Timber::compile_string($template, array('post' => $post));
     $this->assertEquals('Lauren is a&hellip; <a href="' . $post->link() . '" class="read-more">Read More</a>', $str);
 }
 function testCommentCount()
 {
     $post_id = $this->factory->post->create(array('post_title' => 'Gobbles'));
     $comment_id_array = $this->factory->comment->create_many(5, array('comment_post_ID' => $post_id));
     $post = new TimberPost($post_id);
     $this->assertEquals(2, count($post->comments(2)));
     $this->assertEquals(5, $post->get_comment_count());
 }
Esempio n. 6
0
 function testPostMetaFieldFilter()
 {
     $post_id = $this->factory->post->create();
     update_post_meta($post_id, 'Frank', 'Drebin');
     $tp = new TimberPost($post_id);
     add_filter('timber_post_get_meta_field', array($this, 'filter_timber_post_get_meta_field'), 10, 4);
     $this->assertEquals('Drebin', $tp->meta('Frank'));
     remove_filter('timber_post_get_meta_field', array($this, 'filter_timber_post_get_meta_field'));
 }
 /**
  * @Then /^I should have (\d+) imported "([^"]*)" posts$/
  */
 public function iShouldHaveImportedPosts($expectedNumberOfPosts, $categorySlug)
 {
     $query = array('post_type' => 'post', 'meta_query' => array(array('key' => 'automated_testing', 'value' => true)));
     $query = new WP_Query($query);
     $posts = $query->get_posts();
     Assert::assertEquals($expectedNumberOfPosts, count($posts));
     $post = new TimberPost($posts[0]);
     Assert::assertTrue($post->has_term($categorySlug, 'category'));
 }
 /**
  * @group wp_query_hacks
  */
 function testGettingWithCategory()
 {
     $cat = $this->factory->term->create(array('name' => 'News', 'taxonomy' => 'category'));
     $pids = $this->factory->post->create_many(6);
     $cats = $this->factory->post->create_many(3, array('post_category' => array($cat)));
     $cat_post = $this->factory->post->create(array('post_category' => array($cat)));
     $cat_post = new TimberPost($cat_post);
     $this->assertEquals('News', $cat_post->category()->name());
     $posts = Timber::get_posts(array('category' => $cat));
     $this->assertEquals(4, count($posts));
 }
Esempio n. 9
0
 function testTermNotMerged()
 {
     $pid = $this->factory->post->create();
     // create a new tag and associate it with the post
     $dummy_tag = wp_insert_term('whatever', 'post_tag');
     wp_set_object_terms($pid, $dummy_tag['term_id'], 'post_tag', true);
     $dummy_cat = wp_insert_term('thingy', 'category');
     wp_set_object_terms($pid, $dummy_cat['term_id'], 'category', true);
     $post = new TimberPost($pid);
     $terms = $post->terms('all', false);
     $this->assertEquals($terms['post_tag'][0]->name, 'whatever');
 }
Esempio n. 10
0
 function testMultilevelThreadedCommentsCorrectParents()
 {
     $post_id = $this->factory->post->create(array('post_title' => 'Gobbles'));
     $comment_id = $this->factory->comment->create(array('comment_post_ID' => $post_id));
     $comment2_id = $this->factory->comment->create(array('comment_post_ID' => $post_id));
     $comment2_child_id = $this->factory->comment->create(array('comment_post_ID' => $post_id, 'comment_parent' => $comment2_id));
     $comment2_grandchild_id = $this->factory->comment->create(array('comment_post_ID' => $post_id, 'comment_parent' => $comment2_child_id));
     $post = new TimberPost($post_id);
     $comments = $post->get_comments();
     $children = $comments[1]->children();
     $this->assertEquals($comment2_id, $children[0]->comment_parent);
     $grandchild = $children[1];
     $this->assertEquals($comment2_child_id, $grandchild->comment_parent);
 }
Esempio n. 11
0
 /**
  * fb_opengraph
  *
  */
 public static function fb_opengraph()
 {
     $post = new \TimberPost();
     $title = $post->title;
     $description = is_single() ? str_replace('', "'", $post->get_preview(60, true, false, true)) : get_bloginfo('description', 'display');
     $img = has_post_thumbnail($post->id) ? wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large')[0] : (get_theme_mod('og_img') ? get_theme_mod('og_img') : esc_url(get_theme_mod('logo')));
     $type = is_author() ? 'profile' : (is_single() ? 'article' : 'website');
     $url = get_permalink();
     $url = rtrim(esc_url(apply_filters('og_url', $url)));
     if (!substr($url, -1) === '/') {
         $url .= '/';
         // slash fixes Facebook Debugger "Circular Redirect Path"
     }
     $open_graph = array('site_name' => esc_attr(apply_filters('og_site_name', get_bloginfo())), 'title' => esc_attr(apply_filters('og_title', $title)), 'description' => esc_attr(apply_filters('og_description', $description)), 'type' => esc_attr(apply_filters('og_type', $type)), 'url' => $url, 'image' => esc_url(apply_filters('og_image', $img)));
     \Timber::render('open-graph.twig', array('open_graph' => $open_graph));
 }
Esempio n. 12
0
 public function get_title()
 {
     if (!$this->title) {
         $this->title = $this->post->title();
     }
     return $this->title;
 }
Esempio n. 13
0
 function testCommentWithChildren()
 {
     $kramer = $this->factory->user->create(array('display_name' => 'Cosmo Kramer'));
     $post_id = $this->factory->post->create();
     $comment_id = $this->factory->comment->create(array('comment_post_ID' => $post_id, 'comment_content' => 'These pretzels are making me thirsty.', 'user_id' => $kramer));
     sleep(2);
     $comment_id = $this->factory->comment->create(array('comment_post_ID' => $post_id, 'comment_content' => 'Perhaps there’s more to Newman than meets the eye.'));
     $child_id = $this->factory->comment->create(array('comment_post_ID' => $post_id, 'comment_content' => 'No, there’s less.', 'comment_parent' => $comment_id));
     $post = new TimberPost($post_id);
     $comments = $post->get_comments();
     $this->assertEquals(2, count($comments));
     $this->assertEquals(1, count($comments[1]->children));
     $twig_string = '{{comment.author.name}}';
     $result = Timber::compile_string($twig_string, array('comment' => $comments[0]));
     $this->assertEquals('Cosmo Kramer', $result);
 }
Esempio n. 14
0
 /**
  * add meta_description
  *
  * hook after post has loaded to add a unique meta-description
  *
  */
 public static function meta_description()
 {
     $post = new \TimberPost();
     // check for custom field
     $description = wptexturize($post->get_field('meta_description'));
     // else use preview
     if (empty($description)) {
         $description = str_replace('', "'", $post->get_preview(40, true, false, true));
     }
     // finally use the blog description
     if (empty($description)) {
         $description = get_bloginfo('description', 'display');
     }
     $description = esc_attr($description);
     // limit to SEO recommended length
     if (strlen($description) > 155) {
         $description = substr($description, 0, 155);
         $description = \TimberHelper::trim_words($description, str_word_count($description) - 1);
     }
     return $description;
 }
/**
 * Template Name: Subpàgina Programa
 *
 * @package wp-softcatala
 */
wp_enqueue_script('sc-js-pmf', get_template_directory_uri() . '/static/js/pmf.js', array('sc-js-main'), WP_SOFTCATALA_VERSION, true);
wp_enqueue_script('jquery-browser-plugin', get_template_directory_uri() . '/static/js/jquery.browser.min.js', array('sc-js-main'), WP_SOFTCATALA_VERSION, true);
wp_enqueue_script('sc-js-programes', get_template_directory_uri() . '/static/js/programes.js', array('sc-js-main', 'jquery-browser-plugin'), WP_SOFTCATALA_VERSION, true);
wp_localize_script('sc-js-programes', 'scajax', array('ajax_url' => admin_url('admin-ajax.php')));
$context = Timber::get_context();
$post_subpagina = new TimberPost();
$context['sidebar_top'] = Timber::get_widgets('sidebar_top');
$context['sidebar_elements'] = array('baixades.twig', 'links.twig');
$context['sidebar_bottom'] = Timber::get_widgets('sidebar_bottom');
$context['post_subpagina'] = $post_subpagina;
$post = new TimberPost($post_subpagina->programa);
$logo = $post->logotip_programa;
$custom_logo_filter = function ($img) use($logo) {
    return $logo;
};
add_filter('wpseo_twitter_image', $custom_logo_filter);
add_filter('wpseo_opengraph_image', $custom_logo_filter);
$context['post'] = $post;
$context['content_title'] = $post->title . ' - PMF';
$query = array('post_id' => $post_subpagina->programa, 'subpage_type' => 'programa');
$args = get_post_query_args('page', SearchQueryType::PagePrograma, $query);
query_posts($args);
$context['related_pages'] = Timber::get_posts($args);
$baixades = $post->get_field('baixada');
$context['baixades'] = generate_url_download($baixades, $post);
Timber::render(array('subpagina-type.twig'), $context);
Esempio n. 16
0
 function testEditUrl()
 {
     $pid = $this->factory->post->create(array('post_author' => 1));
     $post = new TimberPost($pid);
     $edit_url = $post->edit_link();
     $this->assertEquals('', $edit_url);
     wp_set_current_user(1);
     $data = get_userdata(1);
     $this->assertTrue($post->can_edit());
     $this->assertEquals('http://example.org/wp-admin/post.php?post=' . $pid . '&amp;action=edit', $post->get_edit_url());
     //
 }
 *
 * @package wp-softcatala
 */
$url_api = get_option('api_diccionari_multilingue');
/* JS scripts */
wp_enqueue_script('sc-js-contacte', get_template_directory_uri() . '/static/js/contact_form.js', array('sc-js-main'), WP_SOFTCATALA_VERSION, true);
wp_enqueue_script('sc-js-typeahead', get_template_directory_uri() . '/static/js/typeahead.js', array('sc-js-main'), WP_SOFTCATALA_VERSION, true);
wp_enqueue_script('sc-js-multilingue', get_template_directory_uri() . '/static/js/multilingue.js', array('sc-js-typeahead'), WP_SOFTCATALA_VERSION, true);
wp_localize_script('sc-js-multilingue', 'scajax', array('ajax_url' => admin_url('admin-ajax.php'), 'autocomplete_url' => $url_api . 'autocomplete/'));
$paraula = urldecode(get_query_var('paraula'));
$lletra = get_query_var('lletra');
$content_title = 'Diccionari multilingüe';
$title = '';
$description = '';
$canonical = '';
$post = new TimberPost();
//Ads
$context_holder = array();
$context_holder['ads_container'] = generate_ads_html(array('13', '17'));
if (!empty($paraula)) {
    $url = $url_api . 'search/' . $paraula;
    if (get_query_var('llengua')) {
        $lang = urldecode(get_query_var('llengua'));
        $url = $url . '?lang=' . $lang;
        $context_holder['lang'] = $lang;
    }
    $api_call = do_json_api_call($url);
    if (is_array($api_call)) {
        throw_error('404', 'No Results For This Search');
        $context_holder['cerca_result'] = 'Sembla que la paraula que esteu cercant no es troba al diccionari. Heu seleccionat la llengua correcta?';
    } else {
 public static function get_posts($lists, $manualPosts = null, $limitOverride = null, $offset = 0, $caresAboutDupes = true, $excludePosts = null)
 {
     global $post;
     $context = Timber::get_context();
     if (!is_array($lists)) {
         $lists = array($lists);
     }
     // Add manual which are live
     $posts = array();
     if ($manualPosts) {
         if (!is_array($manualPosts)) {
             $manualPosts = $manualPosts->get_posts();
         }
         foreach ($manualPosts as $manualPost) {
             if (get_post_status($manualPost) === 'publish') {
                 // if (true) {
                 if (is_numeric($manualPost) || get_class($manualPost) === 'WP_Post') {
                     $timberPost = new TimberPost($manualPost);
                     if (!$timberPost) {
                         throw new Exception('Expected Timber to initialise a post');
                     }
                 } else {
                     $timberPost = $manualPost;
                 }
                 $posts[] = $timberPost;
                 if ($caresAboutDupes) {
                     self::$dupes[] = $timberPost->id;
                 }
             }
         }
     }
     $limitOverride = $limitOverride - count($posts);
     // If manual lists already has enough content do not fetch from query
     if ($limitOverride <= 0) {
         return $posts;
     }
     $post_not_in = $caresAboutDupes ? self::$dupes : array();
     if ($excludePosts) {
         foreach ($excludePosts as $excludePost) {
             if (is_numeric($excludePost)) {
                 $post_not_in[] = $excludePost;
             } elseif (get_class($excludePost) === 'WP_Post' || get_class($excludePost) === 'TimberPost') {
                 $post_not_in[] = $excludePost->ID;
             }
         }
     }
     $date = date('Ymd H:i:s');
     $postsFromQuery = [];
     foreach ($lists as $list) {
         if (!$list) {
             continue;
         }
         $list_id = is_numeric($list) ? $list : $list->ID;
         if (!method_exists($list, 'get_field')) {
             $list = new TimberPost($list->ID);
         }
         $categories = [];
         if ($list->get_field('categories_configuration') === 'current-category-and-children') {
             $categories[] = self::get_current_category_from_url();
         } else {
             $categories = get_field("categories", $list_id) ?: [];
         }
         $post_type = null;
         if ($list->get_field('post_type_configuration') === 'current') {
             if ($post && isset($post->post_type)) {
                 $post_type = $post->post_type;
             }
         }
         $query_args = array('cat' => implode(',', $categories), 'posts_per_page' => $limitOverride ? $limitOverride : get_field("limit", $list->ID), 'post__not_in' => $post_not_in, 'no_found_rows' => 1, 'offset' => $offset, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC', 'meta_query' => array('relation' => 'AND', array('relation' => 'OR', array('relation' => 'AND', array('key' => 'override_end_time', 'compare' => 'NOT EXISTS', 'value' => '1'), array('key' => 'override_start_time', 'compare' => 'NOT EXISTS', 'value' => '1')), array('relation' => 'AND', array('relation' => 'OR', array('key' => 'override_end_time', 'compare' => '>=', 'value' => time()), array('key' => 'override_end_time', 'compare' => '==', 'value' => '')), array('relation' => 'OR', array('key' => 'override_start_time', 'compare' => '<=', 'value' => time()), array('key' => 'override_start_time', 'compare' => '==', 'value' => ''))))));
         if ($post_type) {
             $query_args['post_type'] = $post_type;
         }
         $the_query = new WP_Query($query_args);
         // Merge each lists resulting post IDs into
         // $post_not_in to avoid dupes.
         $post_not_in = array_merge($post_not_in, array_map(function ($p) {
             return $p->ID;
         }, $the_query->posts));
         $postsFromQuery = array_merge($postsFromQuery, $the_query->posts);
         // Reduce the limit by amout of posts received.
         $limitOverride -= count($the_query->posts);
         if ($limitOverride <= 0) {
             break;
         }
     }
     foreach ($postsFromQuery as $post) {
         if (get_class($post) === 'WP_Post') {
             $timberPost = new TimberPost($post);
         } else {
             $timberPost = new $post();
         }
         $posts[] = $timberPost;
         if ($caresAboutDupes) {
             self::$dupes[] = $post->ID;
         }
         if (!$timberPost) {
             var_dump($timberPost);
             exit;
         }
     }
     return $posts;
 }
Esempio n. 19
0
 /**
  * @group failing
  */
 function testEditUrl()
 {
     ini_set("log_errors", 1);
     ini_set("error_log", "/tmp/php-error.log");
     global $current_user;
     $current_user = array();
     $uid = $this->factory->user->create(array('display_name' => 'Franklin Delano Roosevelt', 'user_login' => 'fdr'));
     $pid = $this->factory->post->create(array('post_author' => $uid));
     $post = new TimberPost($pid);
     $edit_url = $post->edit_link();
     $this->assertEquals('', $edit_url);
     $user = wp_set_current_user($uid);
     $user->add_role('administrator');
     $data = get_userdata($uid);
     $this->assertTrue($post->can_edit());
     $this->assertEquals('http://example.org/wp-admin/post.php?post=' . $pid . '&amp;action=edit', $post->get_edit_url());
     //
 }
 function testLinkedGuestAuthor()
 {
     global $coauthors_plus;
     $pid = $this->factory->post->create();
     $post = new TimberPost($pid);
     $user_login = '******';
     $display_name = 'True Name';
     $uid = $this->factory->user->create(array('display_name' => $display_name, 'user_login' => $user_login));
     $user = new Timber\User($uid);
     $guest_login = '******';
     $guest_display_name = 'LGuest D Name';
     $guest_id = self::create_guest_author(array('user_login' => $guest_login, 'display_name' => $guest_display_name));
     add_post_meta($guest_id, 'cap-linked_account', $user_login, true);
     $coauthors_plus->add_coauthors($pid, array($user_login));
     $coauthors_plus->force_guest_authors = false;
     $authors = $post->authors();
     $author = $authors[0];
     $this->assertEquals($author->display_name, $user->name);
     $this->assertInstanceOf('Timber\\User', $author);
     $this->assertNotInstanceOf('Timber\\Integrations\\CoAuthorsPlusUser', $author);
     $coauthors_plus->force_guest_authors = true;
     $authors = $post->authors();
     $author = $authors[0];
     $this->assertEquals($author->display_name, $guest_display_name);
     $this->assertInstanceOf('Timber\\Integrations\\CoAuthorsPlusUser', $author);
 }
Esempio n. 21
0
 function testPostTerms()
 {
     register_taxonomy('team', 'post');
     $teams = array('Patriots', 'Bills', 'Dolphins', 'Jets');
     foreach ($teams as &$team) {
         $team_terms[] = wp_insert_term($team, 'team');
     }
     $pid = $this->factory->post->create();
     foreach ($team_terms as $team) {
         wp_set_object_terms($pid, $team['term_id'], 'team', true);
     }
     $post = new TimberPost($pid);
     $teams = $post->terms('team');
     $this->assertEquals(4, count($teams));
     $tag = wp_insert_term('whatever', 'post_tag');
     wp_set_object_terms($pid, $tag['term_id'], 'post_tag', true);
     $post = new TimberPost($pid);
     $this->assertEquals(6, count($post->terms()));
     $tags = $post->tags();
     $this->assertEquals('whatever', $tags[0]->slug);
     $tags = $post->terms('tag');
     $this->assertEquals('whatever', $tags[0]->slug);
     $this->assertTrue($post->has_term('Dolphins'));
     $this->assertTrue($post->has_term('Patriots', 'team'));
 }
Esempio n. 22
0
 function testPreviewWithCustomMoreTag()
 {
     $pid = $this->factory->post->create(array('post_content' => 'Eric is a polar bear <!-- more But what is Elaina? --> Lauren is not a duck', 'post_excerpt' => ''));
     $post = new TimberPost($pid);
     $this->assertEquals('Eric is a polar bear <a href="' . $post->link() . '" class="read-more">But what is Elaina?</a>', $post->get_preview());
 }
Esempio n. 23
0
<?php

/**
 * Template Name: Homepage
 */
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 = Timber::get_context();
$pi = new TimberPost();
$produtos = new TimberPost($pi->produtos);
$context['post'] = $pi->title();
Timber::render(array('home.twig'), $context);
Esempio n. 24
0
<?php

/**
 * The Template for displaying all single posts
 *
 * Methods for TimberHelper can be found in the /functions sub-directory
 *
 * @package  WordPress
 * @subpackage  Timber
 * @since    Timber 0.1
 */
$context = Timber::get_context();
$post = new TimberPost();
$context['post'] = $post;
$context['wp_title'] .= ' - ' . $post->title();
$context['comment_form'] = TimberHelper::get_comment_form();
Timber::render(array('single-' . $post->ID . '.twig', 'single-' . $post->post_type . '.twig', 'single.twig'), $context);
Esempio n. 25
0
    $projecte->lectures_recomanades = apply_filters('the_content', $projecte->lectures_recomanades);
    $context_filterer = new SC_ContextFilterer();
    $context = $context_filterer->get_filtered_context(array('title' => $content_title . '| Softcatalà'));
    $context['projecte'] = $projecte;
    $context['steps'] = $projecte->get_field('steps');
    $templates = array('plantilla-steps-single.twig');
    $args = array('meta_query' => array(get_meta_query_value('projectes', $projecte->ID, 'like', '')));
    $context['membres'] = get_users($args);
} else {
    $post = Timber::get_post();
    $profile = $post->get_field('perfil');
    $profile_label = get_field_object('perfil', $post->ID);
    $all_acf_data = get_field_objects($post->ID);
    $content_title = 'Col·laboreu amb nosaltres: ' . $profile_label['choices'][$profile];
    if (false === $profile || empty($profile)) {
        wp_redirect('/col·laboreu/', 302);
    }
    $project_args = array('tax_query' => array(array('taxonomy' => 'ajuda-projecte', 'field' => 'slug', 'terms' => $profile), array('taxonomy' => 'classificacio', 'field' => 'slug', 'terms' => 'arxivat', 'operator' => 'NOT IN')));
    $projects = $sc_types['projectes']->get_sorted_projects($project_args);
    $context = Timber::get_context();
    $context['projectes'] = $projects;
    $context['steps'] = $post->get_field('steps');
}
$post = new TimberPost();
$context['post'] = $post;
$context['content_title'] = $content_title;
$context['links'] = $post->get_field('link');
$context['sidebar_top'] = Timber::get_widgets('sidebar_top');
$context['sidebar_elements'] = array('static/dubte_forum.twig', 'baixades.twig', 'links.twig');
$context['sidebar_bottom'] = Timber::get_widgets('sidebar_bottom');
Timber::render($templates, $context);
Esempio n. 26
0
<?php

$data = Timber::get_context();
$pi = new TimberPost();
if (isset($pi->banner_image)) {
    $pi->banner_image = new TimberImage($pi->banner_image);
}
$data['post'] = $pi;
if ($pi->custom_title_tag) {
    $data['wp_title'] = $pi->custom_title_tag . ' - Upstatement Blog';
} else {
    $data['wp_title'] = $pi->get_title() . ' - Upstatement Blog';
}
if ($pi->custom_description) {
    $data['meta_desc'] = $pi->custom_description;
} else {
    $data['meta_desc'] = strip_tags($pi->get_preview(30, true, '', true));
}
$data['sidebar'] = Timber::get_sidebar();
if (post_password_required($post->ID)) {
    Timber::render('single-password.twig', $data);
} else {
    Timber::render('single.twig', $data);
}
Esempio n. 27
0
 function add_to_context($context)
 {
     // SITE INFO
     $context['site'] = $this;
     // PRIMARY MENU
     $context['primary_menu'] = array();
     // Loop through each primary menu item
     foreach (get_fields('option')['primary_menu'] as $key => $item) {
         $context['primary_menu'][$key] = $item;
         // Getting parent's info
         $context['primary_menu'][$key]['pm_children'] = array();
         $itemPost = new TimberPost($item['pm_parent']);
         $context['primary_menu'][$key]['pm_label'] = $itemPost->name();
         $context['primary_menu'][$key]['pm_link'] = $itemPost->link();
         // Loop through each primary menu item's children
         foreach ($itemPost->children('page') as $subitem) {
             $context['primary_menu'][$key]['pm_children'][$subitem->name()] = $subitem->link();
         }
     }
     // SECONDARY MENU
     $context['secondary_menu'] = get_fields('option')['secondary_menu'];
     // LANGUAGES
     $context['languages']['english'] = get_fields('option')['english'];
     $context['languages']['indonesian'] = get_fields('option')['indonesian'];
     // MISC MOBILE MENU
     $context['misc_menu'] = get_fields('option')['quicklinks'];
     // FOOTER
     $context['footer']['bg'] = get_fields('option')['footer_bg'];
     $context['footer']['slogan'] = get_fields('option')['footer_slogan'];
     $context['footer']['social'] = get_fields('option')['footer_social'];
     // GLOBAL SETTINGS
     $context['global']['name'] = get_fields('option')['global_name'];
     $context['global']['address'] = get_fields('option')['global_address'];
     $context['global']['contacts'] = get_fields('option')['global_contacts'];
     return $context;
 }
Esempio n. 28
0
<?php

/*
Template Name: Person
*/
/**
 * The template for displaying people pages.
 *
 * This is the template that displays all pages by default.
 * Please note that this is the wordpress construct of pages
 * and that other 'pages' on your wordpress site will use a
 * different template.
 *
 */
$data = Timber::get_context();
$pi = new TimberPost();
$data['post'] = $pi;
$data['wp_title'] = $pi->title() . ' - About Upstatement';
$data['post']->links = get_field('links');
foreach ($data['post']->links as &$link) {
    $link['class'] = 'ss-social';
    if (isset($link['icon']) && $link['icon'] == 'home') {
        $link['class'] = ' ';
    }
}
$data['post']->image = new TimberImage($pi->image);
$data['post']->image_mobile = new TimberImage($pi->image_mobile);
Timber::render(array('page-person-' . $pi->post_name . '.twig', 'page-person.twig'), $data);
 function testDoubleEllipsis()
 {
     $post_id = $this->factory->post->create();
     $post = new TimberPost($post_id);
     $post->post_excerpt = 'this is super dooper trooper long words';
     $prev = $post->get_preview(3, true);
     $this->assertEquals(1, substr_count($prev, '&hellip;'));
 }
Esempio n. 30
0
<?php

/*
Template Name: Team Page
*/
$context = Timber::get_context();
$post = new TimberPost();
$context['post'] = $post;
$context['posts'] = Timber::get_posts('post_type=team-cpt&posts_per_page=-1&orderby=menu_order&order=ASC');
$context['content_column_1'] = $post->content(1);
$context['content_column_2'] = $post->content(2);
$context['content_has_columns'] = strpos($post->post_content, '<!--nextpage-->') !== false;
Timber::render('team.twig', $context);