本文整理汇总了PHP中TimberHelper::transient方法的典型用法代码示例。如果您正苦于以下问题:PHP TimberHelper::transient方法的具体用法?PHP TimberHelper::transient怎么用?PHP TimberHelper::transient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimberHelper
的用法示例。
在下文中一共展示了TimberHelper::transient方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: is_home
<?php
/**
* @package WordPress
* @subpackage Timber
* @since Timber 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 = Timber::get_context();
$context['post'] = Timber::get_post();
$context['is_home'] = is_home() || is_front_page();
if ($context['is_home']) {
$context['site_css_contents'] = TimberHelper::transient('site_css_contents', function () {
return file_get_contents(get_template_directory_uri() . "/assets/dist/css/application.min.css");
}, 14400);
}
$templates = array('home.twig');
Timber::render($templates, $context);
示例2: testTransientAsString
function testTransientAsString()
{
$transient = TimberHelper::transient('jn_test_string', 'my_test_callback', 200);
$this->assertEquals($transient, 'lbj');
}
示例3: testExpireTransient
function testExpireTransient()
{
$transient = $this->_generate_transient_name();
$first_value = TimberHelper::transient($transient, function () {
return 'first_value';
}, 2);
sleep(3);
$second_value = TimberHelper::transient($transient, function () {
return 'second_value';
}, 2);
$this->assertEquals('second_value', $second_value);
}
示例4: 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);