本文整理汇总了PHP中TimberHelper::array_truncate方法的典型用法代码示例。如果您正苦于以下问题:PHP TimberHelper::array_truncate方法的具体用法?PHP TimberHelper::array_truncate怎么用?PHP TimberHelper::array_truncate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimberHelper
的用法示例。
在下文中一共展示了TimberHelper::array_truncate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testArrayTruncate
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));
}
示例2: get_blog_posts
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;
}
示例3: array
<?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) {
示例4: load_script
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')) {
示例5: TimberTerm
$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);
}
示例6: TimberPost
* @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);