archive.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * The template for displaying Archive pages.
  4. *
  5. * Used to display archive-type pages if nothing more specific matches a query.
  6. * For example, puts together date-based pages if no date.php file exists.
  7. *
  8. * Learn more: http://codex.wordpress.org/Template_Hierarchy
  9. *
  10. * Methods for TimberHelper can be found in the /lib sub-directory
  11. *
  12. * @package WordPress
  13. * @subpackage Timber
  14. * @since Timber 0.2
  15. */
  16. $templates = array( 'archive.twig', 'index.twig' );
  17. $context = Timber::context();
  18. $context['title'] = 'Archive';
  19. if ( is_day() ) {
  20. $context['title'] = 'Archive: ' . get_the_date( 'D M Y' );
  21. } elseif ( is_month() ) {
  22. $context['title'] = 'Archive: ' . get_the_date( 'M Y' );
  23. } elseif ( is_year() ) {
  24. $context['title'] = 'Archive: ' . get_the_date( 'Y' );
  25. } elseif ( is_tag() ) {
  26. $context['title'] = single_tag_title( '', false );
  27. } elseif ( is_category() ) {
  28. $context['title'] = single_cat_title( '', false );
  29. array_unshift( $templates, 'archive-' . get_query_var( 'cat' ) . '.twig' );
  30. } elseif ( is_post_type_archive() ) {
  31. $context['title'] = post_type_archive_title( '', false );
  32. array_unshift( $templates, 'archive-' . get_post_type() . '.twig' );
  33. }
  34. $context['posts'] = new Timber\PostQuery();
  35. Timber::render( $templates, $context );