本文整理汇总了PHP中Timber::add_route方法的典型用法代码示例。如果您正苦于以下问题:PHP Timber::add_route方法的具体用法?PHP Timber::add_route怎么用?PHP Timber::add_route使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timber
的用法示例。
在下文中一共展示了Timber::add_route方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFailedRoute
function testFailedRoute()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
global $matches;
$matches = array();
$phpunit = $this;
Timber::add_route('foo', function () use($phpunit) {
$phpunit->assertTrue(false);
$matches[] = true;
});
$this->go_to(home_url('bar'));
global $timber;
$timber->init_routes();
$this->assertEquals(0, count($matches));
}
示例2: add_to_twig
function add_to_twig($twig)
{
/* this is where you can add your own fuctions to twig */
$twig->addExtension(new Twig_Extension_StringLoader());
$twig->addFilter('myfoo', new Twig_Filter_Function('myfoo'));
return $twig;
}
}
new StarterSite();
function myfoo($text)
{
$text .= ' bar!';
return $text;
}
Timber::add_route('guests', function ($params) {
Timber::load_view('guests.php', null, 200, $params);
});
function cc_mime_types($mimes)
{
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
function annointed_admin_bar_remove()
{
global $wp_admin_bar;
/* Remove their stuff */
$wp_admin_bar->remove_menu('wp-logo');
}
function remove_menus()
{
remove_menu_page('edit-comments.php');
示例3: add_action
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')) {
$dashboard = new ChainsawDashboard('wp-content/themes/blades/blades-dashboard.json');
}
示例4: get_currentuserinfo
global $current_user;
get_currentuserinfo();
$has_comment = get_comments(array('user_id' => $current_user->ID, 'meta_key' => 'projeto', 'meta_value' => $params['name']));
if (count($has_comment) > 0) {
//redirecionar para pagina de resultado
$voting = '';
foreach ($has_comment as $comment) {
$voting .= $comment->comment_content . ',';
}
header('Location: ' . get_bloginfo('url') . '/projetos/' . $params['name'] . '/resultados?answered=1&voting=' . $voting);
exit;
}
$query = 'posts_per_page=12&post_type=avaliacao&cat_name=' . $params['name'];
Timber::load_template('archive.php', $query);
});
Timber::add_route('projetos/:name/resultados', function ($params) {
if (!is_user_logged_in()) {
wp_redirect(get_bloginfo('url') . '/entrar/?redirect_to=' . get_bloginfo('url') . '/projetos/' . $params['name'] . '/resultados');
exit;
}
$query = 'category_name=' . $params['name'] . '&posts_per_page=12&post_type=avaliacao';
Timber::load_template('resultado-passo-1.php', $query);
});
Timber::add_route('projetos/:name/resultado-geral', function ($params) {
$query = 'category_name=' . $params['name'];
Timber::load_template('resultado-passo-1-geral.php', $query);
});
Timber::add_route('projetos/:name/:user', function ($params) {
$query = 'category_name=' . $params['name'] . '&posts_per_page=12&post_type=avaliacao&username=' . $params['user'];
Timber::load_template('resultado-passo-1.php', $query);
});
示例5: foreach
foreach ($values as $value) {
if (array_search($value, $array) !== false) {
return true;
} else {
return false;
}
}
}
function matchesAny($matcher, $values)
{
foreach ($values as $value) {
if ($matcher === $value) {
return true;
}
}
}
/* NEWS PAGINATION */
Timber::add_route('news', function () {
$page = 0;
$query = array('post_type' => 'post', 'posts_per_page' => 2, 'offset' => $page * 2);
query_posts($query);
Timber::load_template('archive.php');
});
Timber::add_route('news/page/:pg', function ($params) {
$page = $params['pg'];
$page = max(0, $page);
$page = $page;
$query = array('post_type' => 'post', 'posts_per_page' => 2, 'paged' => $page);
query_posts($query);
Timber::load_template('archive.php');
});
示例6: function
<?php
Timber::add_route('/makerspaces', function () {
die(json_encode(Timber::get_posts('post_type=makerspace')));
});
示例7: testVerySimpleRoutePreceedingSlash
function testVerySimpleRoutePreceedingSlash()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
global $matches;
$matches = array();
$phpunit = $this;
Timber::add_route('/gobbles', function () use($phpunit) {
global $matches;
$matches = array();
$matches[] = true;
});
$this->go_to(home_url('gobbles'));
$this->matchRoutes();
$this->assertEquals(1, count($matches));
}
示例8: SustainableSite
}
}
new SustainableSite();
if (function_exists('acf_add_options_page')) {
acf_add_options_page(array('page_title' => 'General Theme Settings', 'menu_title' => 'Theme Settings', 'menu_slug' => 'theme-settings', 'capability' => 'edit_posts', 'redirect' => false));
}
Timber::add_route('posts/get/:offset', function ($params) {
$intPostsPerPage = intval(get_option('posts_per_page'));
$intOffset = intval($params['offset']);
$strPostType = $_POST['post_type'] ? $_POST['post_type'] : 'post';
$strQuery = 'posts_per_page=' . ($intPostsPerPage + 1) . '&post_type=' . $strPostType . '&offset=' . ($intOffset > 0 ? $intOffset : 0);
if ($strPostType === 'portfolio-cpt') {
$strQuery .= '&orderby=menu_order&order=ASC';
}
$arrPosts = Timber::get_posts($strQuery);
$blnHasMore = count($arrPosts) < $intPostsPerPage + 1 ? false : true;
// Remove the last post if we got the number of posts we asked for
if ($blnHasMore) {
array_pop($arrPosts);
}
$strRet = Timber::compile('partials/ajax-results.twig', array('posts' => $arrPosts, 'post_type' => $strPostType));
$arrRet = array('posts' => $arrPosts, 'markup' => $strRet, 'hasMore' => $blnHasMore, 'offset' => $intOffset + $intPostsPerPage, 'query' => $strQuery);
echo json_encode($arrRet);
exit;
});
function my_login_logo()
{
?>
<style type="text/css">
.login h1 a {
background-image: url(<?php