function testArrayTruncate()
 {
     $arr = array('Buster', 'GOB', 'Michael', 'Lindsay');
     $arr = TimberHelper::array_truncate($arr, 2);
     $this->assertContains('Buster', $arr);
     $this->assertEquals(2, count($arr));
     $this->assertFalse(in_array('Lindsay', $arr));
 }
Beispiel #2
0
 public static function get_blog_posts()
 {
     $data = Timber::get_posts('post_type=post&posts_per_page=6');
     $data = TimberHelper::array_truncate($data, 6);
     return $data;
 }
<?php

$data = Timber::get_context();
$data['wp_title'] = 'Upstatement - Portfolio';
$entry_manual = array();
$entries = get_field('entries', 'option');
if ($entries) {
    foreach ($entries as $e) {
        $entry_manual[] = $e->ID;
    }
}
$entry_manual = TimberHelper::array_truncate($entry_manual, 3);
$fp = new TimberPost(3251);
$fp->squares = get_field('squares', $fp->ID);
$billboards = array();
$billboard_ids = array();
foreach ($fp->squares as $square) {
    $bb = new TimberPost($square);
    $billboard_ids[] = $bb->ID;
    $bb->billboard = new TimberImage($bb->billboard);
    if (isset($bb->hero_tease)) {
        $bb->hero_tease = new TimberImage($bb->hero_tease);
    }
    $billboards[] = $bb;
}
// $data['billboards'] = array_slice($billboards, 0, 5);
// $data['plist'] = array_slice($billboards, 5);
$data['billboards'] = $billboards;
$data['clients'] = Timber::get_posts(array('post_type' => 'portfolio', 'numberposts' => -1, 'post__not_in' => $billboard_ids));
$portfolio_client_names = array();
foreach ($data['clients'] as $client) {
Beispiel #4
0
    load_script('scrollTo', get_stylesheet_directory_uri() . '/components/jquery.scrollTo/jquery.scrollTo.js', 1);
}
add_action('wp_enqueue_scripts', 'load_scripts');
update_option('siteurl', 'http://' . $_SERVER['HTTP_HOST']);
update_option('home', 'http://' . $_SERVER['HTTP_HOST']);
if (class_exists('Timber')) {
    Timber::add_route('blog', function ($params) {
        $sticky = get_option('sticky_posts');
        $sticky = TimberHelper::array_truncate($sticky, 4);
        $page = 0;
        $query = array('post_type' => 'post', 'posts_per_page' => 6, 'post__not_in' => $sticky, 'offset' => $page * 6);
        Timber::load_template('archive-blog.php', $query);
    });
    Timber::add_route('blog/page/:pg', function ($params) {
        $sticky = get_option('sticky_posts');
        $sticky = TimberHelper::array_truncate($sticky, 4);
        $page = $params['pg'];
        $page -= 1;
        $page = max(0, $page);
        $query = array('post_type' => 'post', 'posts_per_page' => 6, 'post__not_in' => $sticky, 'offset' => $page * 6);
        Timber::load_template('archive-blog.php', $query);
    });
}
if (class_exists('BladesSite')) {
    BladesSite::register_post_types();
    BladesSite::apply_admin_customizations();
    add_action('init', function () {
        BladesSite::register_post_types();
    });
}
if (class_exists('ChainsawDashboard')) {
Beispiel #5
0
$data = Timber::get_context();
global $wp_query;
$api = false;
if (isset($_GET['api'])) {
    $api = $_GET['api'];
}
$data['base'] = 'base.twig';
if ($api) {
    $data['base'] = 'base-blank.twig';
}
$page = 0;
if ($wp_query->query_vars['paged']) {
    $page = $wp_query->query_vars['paged'];
}
$term = new TimberTerm();
$data['title'] = "Archives for " . $term->name;
$data['blog_cron'] = Timber::get_posts();
$data['tags'] = Timber::get_terms(array('tax' => 'tags', 'orderby' => 'count'));
shuffle($data['tags']);
$data['tags'] = TimberHelper::array_truncate($data['tags'], 10);
$next_page = $page + 1;
if ($page == 0) {
    $next_page = 2;
}
if ($api) {
    Timber::render('archive-blog-loop.twig', $data);
} else {
    $data['sidebar'] = Timber::get_sidebar('sidebar.php');
    Timber::render('archive-blog.twig', $data);
}
Beispiel #6
0
 * @since Boilerplate 1.0
 */
$data = Timber::get_context();
$pi = new TimberPost();
$data['post'] = $pi;
$data['body_class'] .= ' page-' . $pi->post_name;
$template_file = 'page.twig';
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $data['theme_dir'] . '/css/' . $pi->post_type . '-' . $post->post_name . '.css')) {
    $data['post']->css_file = $data['theme_dir'] . '/css/' . $pi->post_type . '-' . $post->post_name . '.css';
}
$contribs = TimberHelper::transient('timber-contribs', function () {
    require_once __DIR__ . '/vendor/tan-tan-kanarek/github-php-client/tan-tan-kanarek/github-php-client/client/GitHubClient.php';
    $client = new GitHubClient();
    $auth = file_get_contents(__DIR__ . '/auth.json');
    $auth = json_decode($auth);
    $client->setCredentials($auth->github->user, $auth->github->pass);
    $contribs = $client->repos->listContributors('jarednova', 'timber', array('per_page' => 100));
    $extra = count($contribs) % 6;
    $total = count($contribs) - $extra;
    $contribs = TimberHelper::array_truncate($contribs, $total);
    $ret = array();
    foreach ($contribs as $contrib) {
        $obj = new stdClass();
        $obj->login = $contrib->getLogin();
        $obj->avatar_url = $contrib->getAvatarUrl();
        $ret[] = $obj;
    }
    return $ret;
}, 1200);
$data['contribs'] = $contribs;
Timber::render(array('custom/page-' . $pi->post_name . '.twig', 'page-' . $pi->post_name . '.twig', 'page.twig'), $data);