Skip to content

Instantly share code, notes, and snippets.

@davidmaneuver
Last active November 12, 2018 16:48
Show Gist options
  • Save davidmaneuver/876213b3b138a1b3df7616cdabf50e84 to your computer and use it in GitHub Desktop.
Save davidmaneuver/876213b3b138a1b3df7616cdabf50e84 to your computer and use it in GitHub Desktop.
<?php
/**
* Get context.
**/
$context = Timber::get_context();
/**
* Retrieve current language.
**/
$locale = get_bloginfo('language');
$context['lang'] = substr($locale, 0, 2);
/**
* Load in defined menus.
**/
if ($locs = get_nav_menu_locations()) {
foreach ($locs as $name => $id) {
$context['menus'][$name] = new TimberMenu($id);
}
}
/**
* Retrieve posts.
**/
if (is_singular()) {
$context['post'] = \Timber::get_post();
$context['is_preview'] = is_preview();
} else {
$context['posts'] = \Timber::get_posts();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment