Advertisement
alchymyth

2011 show all posts as recent posts and all full

Jun 10th, 2015
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.37 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Template Name: Showcase Template
  4.  *
  5.  * Description: A Page Template that showcases Sticky Posts, Asides, and Blog Posts.
  6.  *
  7.  * The showcase template in Twenty Eleven consists of a featured posts section using sticky posts,
  8.  * another recent posts area (with the latest post shown in full and the rest as a list)
  9.  * and a left sidebar holding aside posts.
  10.  *
  11.  * We are creating two queries to fetch the proper posts and a custom widget for the sidebar.
  12.  *
  13.  * @package WordPress
  14.  * @subpackage Twenty_Eleven
  15.  * @since Twenty Eleven 1.0
  16.  */
  17.  
  18. // Enqueue showcase script for the slider
  19. wp_enqueue_script( 'twentyeleven-showcase', get_template_directory_uri() . '/js/showcase.js', array( 'jquery' ), '2011-04-28' );
  20.  
  21. get_header(); ?>
  22.  
  23.         <div id="primary" class="showcase">
  24.             <div id="content" role="main">
  25.  
  26.                 <?php while ( have_posts() ) : the_post(); ?>
  27.  
  28.                 <?php
  29.                     /*
  30.                      * We are using a heading by rendering the_content
  31.                      * If we have content for this page, let's display it.
  32.                      */
  33.                     if ( '' != get_the_content() )
  34.                         get_template_part( 'content', 'intro' );
  35.                 ?>
  36.  
  37.                 <?php endwhile; ?>
  38.  
  39.                 <?php
  40.                     /*
  41.                      * Begin the featured posts section.
  42.                      *
  43.                      * See if we have any sticky posts and use them to create our featured posts.
  44.                      * We limit the featured posts at ten.
  45.                      */
  46.                     $sticky = get_option( 'sticky_posts' );
  47.  
  48.                     // Proceed only if sticky posts exist.
  49.                     if ( ! empty( $sticky ) ) :
  50.  
  51.                     $featured_args = array(
  52.                         'post__in' => $sticky,
  53.                         'post_status' => 'publish',
  54.                         'posts_per_page' => 10,
  55.                         'no_found_rows' => true,
  56.                     );
  57.  
  58.                     // The Featured Posts query.
  59.                     $featured = new WP_Query( $featured_args );
  60.  
  61.                     // Proceed only if published posts exist
  62.                     if ( $featured->have_posts() ) :
  63.  
  64.                     /*
  65.                      * We will need to count featured posts starting from zero
  66.                      * to create the slider navigation.
  67.                      */
  68.                     $counter_slider = 0;
  69.  
  70.                     // Compatibility with versions of WordPress prior to 3.4.
  71.                     if ( function_exists( 'get_custom_header' ) )
  72.                         $header_image_width = get_theme_support( 'custom-header', 'width' );
  73.                     else
  74.                         $header_image_width = HEADER_IMAGE_WIDTH;
  75.                 ?>
  76.  
  77.                 <div class="featured-posts">
  78.                     <h1 class="showcase-heading"><?php _e( 'Featured Post', 'twentyeleven' ); ?></h1>
  79.  
  80.                 <?php
  81.                     // Let's roll.
  82.                     while ( $featured->have_posts() ) : $featured->the_post();
  83.  
  84.                     // Increase the counter.
  85.                     $counter_slider++;
  86.  
  87.                     /*
  88.                      * We're going to add a class to our featured post for featured images
  89.                      * by default it'll have the feature-text class.
  90.                      */
  91.                     $feature_class = 'feature-text';
  92.  
  93.                     if ( has_post_thumbnail() ) {
  94.                         // ... but if it has a featured image let's add some class
  95.                         $feature_class = 'feature-image small';
  96.  
  97.                         // Hang on. Let's check this here image out.
  98.                         $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, $header_image_width ) );
  99.  
  100.                         // Is it bigger than or equal to our header?
  101.                         if ( $image[1] >= $header_image_width ) {
  102.                             // If bigger, let's add a BIGGER class. It's EXTRA classy now.
  103.                             $feature_class = 'feature-image large';
  104.                         }
  105.                     }
  106.                     ?>
  107.  
  108.                     <section class="featured-post <?php echo esc_attr( $feature_class ); ?>" id="featured-post-<?php echo esc_attr( $counter_slider ); ?>">
  109.  
  110.                         <?php
  111.                             /*
  112.                              * If the thumbnail is as big as the header image
  113.                              * make it a large featured post, otherwise render it small
  114.                              */
  115.                             if ( has_post_thumbnail() ) {
  116.                                 if ( $image[1] >= $header_image_width )
  117.                                     $thumbnail_size = 'large-feature';
  118.                                 else
  119.                                     $thumbnail_size = 'small-feature';
  120.                                 ?>
  121.                                 <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_post_thumbnail( $thumbnail_size ); ?></a>
  122.                                 <?php
  123.                             }
  124.                         ?>
  125.                         <?php get_template_part( 'content', 'featured' ); ?>
  126.                     </section>
  127.                 <?php endwhile; ?>
  128.  
  129.                 <?php
  130.                     // Show slider only if we have more than one featured post.
  131.                     if ( $featured->post_count > 1 ) :
  132.                 ?>
  133.                 <nav class="feature-slider">
  134.                     <ul>
  135.                     <?php
  136.  
  137.                         // Reset the counter so that we end up with matching elements
  138.                         $counter_slider = 0;
  139.  
  140.                         // Begin from zero
  141.                         rewind_posts();
  142.  
  143.                         // Let's roll again.
  144.                         while ( $featured->have_posts() ) : $featured->the_post();
  145.                             $counter_slider++;
  146.                             if ( 1 == $counter_slider )
  147.                                 $class = ' class="active"';
  148.                             else
  149.                                 $class = '';
  150.                         ?>
  151.                         <li><a href="#featured-post-<?php echo esc_attr( $counter_slider ); ?>" title="<?php echo esc_attr( sprintf( __( 'Featuring: %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ) ); ?>"<?php echo $class; ?>></a></li>
  152.                     <?php endwhile; ?>
  153.                     </ul>
  154.                 </nav>
  155.                 <?php endif; // End check for more than one sticky post. ?>
  156.                 </div><!-- .featured-posts -->
  157.                 <?php endif; // End check for published posts. ?>
  158.                 <?php endif; // End check for sticky posts. ?>
  159.  
  160.                 <section class="recent-posts">
  161.                     <h1 class="showcase-heading"><?php _e( 'Recent Posts', 'twentyeleven' ); ?></h1>
  162.  
  163.                     <?php
  164.  
  165.                     // Display our recent posts, showing full content for the very latest, ignoring Aside posts.
  166.                     $recent_args = array(
  167.                                                 'order' => 'DESC',
  168.                                                 'post__not_in' => get_option( 'sticky_posts' ),
  169.                                                 'posts_per_page' => -1, //TYPO FIXED
  170.                                                 'tax_query' => array(
  171.                                                         array(
  172.                                                                 'taxonomy' => 'post_format',
  173.                                                                 'terms' => array( 'post-format-aside', 'post-format-link', 'post-format-quote', 'post-format-status' ),
  174.                                                                 'field' => 'slug',
  175.                                                                 'operator' => 'NOT IN',
  176.                                                         ),
  177.                                                 ),
  178.                                                 'no_found_rows' => true,
  179.                                         );
  180.  
  181.                     // Our new query for the Recent Posts section.
  182.                     $recent = new WP_Query( $recent_args );
  183.  
  184.                     // ADAPTATION
  185.                     // all Recent post are displayed normally and fully
  186.                     if ( $recent->have_posts() ) : while( $recent->have_posts() ) : $recent->the_post();
  187.  
  188.                         // Set $more to 0 in order to only get the first part of the post.
  189.                         global $more;
  190.                         $more = 0;
  191.  
  192.                         get_template_part( 'content', get_post_format() );
  193.  
  194.                     endwhile;
  195.  
  196.                     endif;
  197.                 ?>
  198.                 </section><!-- .recent-posts -->
  199.  
  200.  
  201.                 <div class="widget-area" role="complementary">
  202.                     <?php if ( ! dynamic_sidebar( 'sidebar-2' ) ) : ?>
  203.  
  204.                         <?php
  205.                         the_widget( 'Twenty_Eleven_Ephemera_Widget', '', array( 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
  206.                         ?>
  207.  
  208.                     <?php endif; // end sidebar widget area ?>
  209.                 </div> <!-- .widget-area -->
  210.  
  211.             </div><!-- #content -->
  212.         </div><!-- #primary -->
  213.  
  214. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement