Advertisement
sarahn

Twenty_Twelve category.php

Dec 24th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. <?php
  2. /**
  3. * The modified template for displaying Category pages.
  4. *
  5. * Display original if translation does not exist.
  6. *
  7. * Used to display archive-type pages for posts in a category.
  8. *
  9. * @link http://codex.wordpress.org/Template_Hierarchy
  10. *
  11. * @package WordPress
  12. * @subpackage Twenty_Twelve
  13. * @since Twenty Twelve 1.0
  14. */
  15.  
  16. get_header();
  17.  
  18. // WPML support
  19. global $sitepress;
  20. // save current language
  21. $current_lang = $sitepress->get_current_language();
  22. //get the default language
  23. $default_lang = $sitepress->get_default_language();
  24. //fetch posts in default language
  25. $sitepress->switch_lang($default_lang);
  26. $cat = get_query_var('cat');
  27. //query args
  28. $custom_query_args = array(
  29. 'cat' => icl_object_id($cat, 'category', FALSE,'en')
  30. );
  31.  
  32. //build query
  33. $custom_query = new wp_query($custom_query_args);
  34. //\ WPML support
  35. ?>
  36.  
  37. <section id="primary" class="site-content">
  38. <div id="content" role="main">
  39.  
  40. <?php
  41. // WPML support
  42. if ( $custom_query->have_posts() ) :
  43. //\ WPML support
  44. ?>
  45. <header class="archive-header">
  46. <h1 class="archive-title"><?php printf( __( 'Category Archives: %s', 'twentytwelve' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?></h1>
  47.  
  48. <?php if ( category_description() ) : // Show an optional category description ?>
  49. <div class="archive-meta"><?php echo category_description(); ?></div>
  50. <?php endif; ?>
  51. </header><!-- .archive-header -->
  52.  
  53. <?php
  54. /* Start the Loop */
  55. // WPML support
  56. while ( $custom_query->have_posts() ) : $custom_query->the_post();
  57. //check if a translation exist
  58. $t_post_id = icl_object_id($post->ID, 'post', false, $current_lang);
  59. if(!is_null($t_post_id)){
  60. // get the post object
  61. $t_post = get_post( $t_post_id);
  62. // include the output code
  63. include (get_stylesheet_directory() . '/content-t.php');
  64. }
  65. //no translation? display default language
  66. else{
  67. /* Include the post format-specific template for the content. If you want to
  68. * this in a child theme then include a file called called content-___.php
  69. * (where ___ is the post format) and that will be used instead.
  70. */
  71. get_template_part( 'content', get_post_format() );
  72. }
  73. endwhile;
  74. wp_reset_query();
  75. $sitepress->switch_lang($current_lang);
  76. //\ WPML support
  77.  
  78. twentytwelve_content_nav( 'nav-below' );
  79. ?>
  80.  
  81. <?php else : ?>
  82. <?php get_template_part( 'content', 'none' ); ?>
  83. <?php endif; ?>
  84.  
  85. </div><!-- #content -->
  86. </section><!-- #primary -->
  87.  
  88. <?php get_sidebar(); ?>
  89. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement