2011-04-20 23:46:33 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Template Name: Showcase Template
|
2013-09-25 18:50:11 +02:00
|
|
|
*
|
|
|
|
* Description: A Page Template that showcases Sticky Posts, Asides, and Blog Posts.
|
2011-04-20 23:46:33 +02:00
|
|
|
*
|
2011-04-29 02:19:02 +02:00
|
|
|
* The showcase template in Twenty Eleven consists of a featured posts section using sticky posts,
|
|
|
|
* another recent posts area (with the latest post shown in full and the rest as a list)
|
|
|
|
* and a left sidebar holding aside posts.
|
|
|
|
*
|
|
|
|
* We are creating two queries to fetch the proper posts and a custom widget for the sidebar.
|
|
|
|
*
|
2011-04-20 23:46:33 +02:00
|
|
|
* @package WordPress
|
2011-05-18 21:06:09 +02:00
|
|
|
* @subpackage Twenty_Eleven
|
2011-05-02 23:04:44 +02:00
|
|
|
* @since Twenty Eleven 1.0
|
2011-04-20 23:46:33 +02:00
|
|
|
*/
|
|
|
|
|
2011-04-29 02:19:02 +02:00
|
|
|
// Enqueue showcase script for the slider
|
|
|
|
wp_enqueue_script( 'twentyeleven-showcase', get_template_directory_uri() . '/js/showcase.js', array( 'jquery' ), '2011-04-28' );
|
|
|
|
|
2011-04-20 23:46:33 +02:00
|
|
|
get_header(); ?>
|
|
|
|
|
|
|
|
<div id="primary" class="showcase">
|
|
|
|
<div id="content" role="main">
|
2011-04-26 20:34:52 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
<?php
|
|
|
|
while ( have_posts() ) :
|
|
|
|
the_post();
|
|
|
|
?>
|
2011-04-26 20:34:52 +02:00
|
|
|
|
2011-04-20 23:46:33 +02:00
|
|
|
<?php
|
2013-10-09 22:39:09 +02:00
|
|
|
/*
|
2011-04-29 02:19:02 +02:00
|
|
|
* We are using a heading by rendering the_content
|
|
|
|
* If we have content for this page, let's display it.
|
|
|
|
*/
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( '' != get_the_content() ) {
|
|
|
|
get_template_part( 'content', 'intro' );
|
|
|
|
}
|
2011-04-20 23:46:33 +02:00
|
|
|
?>
|
2011-04-26 20:34:52 +02:00
|
|
|
|
2011-11-21 17:20:49 +01:00
|
|
|
<?php endwhile; ?>
|
|
|
|
|
2011-04-20 23:46:33 +02:00
|
|
|
<?php
|
2013-10-09 22:39:09 +02:00
|
|
|
/*
|
2011-04-29 02:19:02 +02:00
|
|
|
* Begin the featured posts section.
|
|
|
|
*
|
|
|
|
* See if we have any sticky posts and use them to create our featured posts.
|
2011-05-03 22:16:34 +02:00
|
|
|
* We limit the featured posts at ten.
|
2011-04-29 02:19:02 +02:00
|
|
|
*/
|
2011-04-20 23:46:33 +02:00
|
|
|
$sticky = get_option( 'sticky_posts' );
|
2011-06-09 18:39:40 +02:00
|
|
|
|
|
|
|
// Proceed only if sticky posts exist.
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! empty( $sticky ) ) :
|
2011-06-09 18:39:40 +02:00
|
|
|
|
2011-04-20 23:46:33 +02:00
|
|
|
$featured_args = array(
|
2017-12-01 00:11:00 +01:00
|
|
|
'post__in' => $sticky,
|
|
|
|
'post_status' => 'publish',
|
2011-05-10 00:54:55 +02:00
|
|
|
'posts_per_page' => 10,
|
2017-12-01 00:11:00 +01:00
|
|
|
'no_found_rows' => true,
|
2011-04-20 23:46:33 +02:00
|
|
|
);
|
2011-04-26 20:34:52 +02:00
|
|
|
|
2011-04-29 02:19:02 +02:00
|
|
|
// The Featured Posts query.
|
2011-05-10 01:15:38 +02:00
|
|
|
$featured = new WP_Query( $featured_args );
|
2011-06-11 17:44:06 +02:00
|
|
|
|
2011-06-09 18:53:01 +02:00
|
|
|
// Proceed only if published posts exist
|
|
|
|
if ( $featured->have_posts() ) :
|
2011-04-26 20:34:52 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
/*
|
|
|
|
* We will need to count featured posts starting from zero
|
|
|
|
* to create the slider navigation.
|
|
|
|
*/
|
|
|
|
$counter_slider = 0;
|
2011-04-29 02:19:02 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
// Compatibility with versions of WordPress prior to 3.4.
|
|
|
|
if ( function_exists( 'get_custom_header' ) ) {
|
|
|
|
$header_image_width = get_theme_support( 'custom-header', 'width' );
|
|
|
|
} else {
|
|
|
|
$header_image_width = HEADER_IMAGE_WIDTH;
|
|
|
|
}
|
|
|
|
?>
|
2011-04-29 02:19:02 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
<div class="featured-posts">
|
2011-04-29 02:19:02 +02:00
|
|
|
<h1 class="showcase-heading"><?php _e( 'Featured Post', 'twentyeleven' ); ?></h1>
|
|
|
|
|
|
|
|
<?php
|
2017-12-01 00:11:00 +01:00
|
|
|
// Let's roll.
|
|
|
|
while ( $featured->have_posts() ) :
|
|
|
|
$featured->the_post();
|
2011-04-26 20:34:52 +02:00
|
|
|
|
2011-04-29 02:19:02 +02:00
|
|
|
// Increase the counter.
|
|
|
|
$counter_slider++;
|
2011-04-26 20:34:52 +02:00
|
|
|
|
2013-10-09 22:39:09 +02:00
|
|
|
/*
|
2017-12-01 00:11:00 +01:00
|
|
|
* We're going to add a class to our featured post for featured images
|
|
|
|
* by default it'll have the feature-text class.
|
|
|
|
*/
|
2011-06-11 07:07:18 +02:00
|
|
|
$feature_class = 'feature-text';
|
2011-04-20 23:46:33 +02:00
|
|
|
|
|
|
|
if ( has_post_thumbnail() ) {
|
2011-04-29 02:19:02 +02:00
|
|
|
// ... but if it has a featured image let's add some class
|
2011-04-20 23:46:33 +02:00
|
|
|
$feature_class = 'feature-image small';
|
|
|
|
|
|
|
|
// Hang on. Let's check this here image out.
|
2012-03-20 22:32:42 +01:00
|
|
|
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, $header_image_width ) );
|
2011-04-20 23:46:33 +02:00
|
|
|
|
|
|
|
// Is it bigger than or equal to our header?
|
2012-03-20 22:32:42 +01:00
|
|
|
if ( $image[1] >= $header_image_width ) {
|
2011-04-29 02:19:02 +02:00
|
|
|
// If bigger, let's add a BIGGER class. It's EXTRA classy now.
|
2011-04-20 23:46:33 +02:00
|
|
|
$feature_class = 'feature-image large';
|
|
|
|
}
|
|
|
|
}
|
2011-04-26 20:34:52 +02:00
|
|
|
?>
|
2011-06-11 07:07:18 +02:00
|
|
|
|
2015-01-22 01:42:23 +01:00
|
|
|
<section class="featured-post <?php echo esc_attr( $feature_class ); ?>" id="featured-post-<?php echo esc_attr( $counter_slider ); ?>">
|
2011-06-11 17:44:06 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* If the thumbnail is as big as the header image
|
|
|
|
* make it a large featured post, otherwise render it small
|
|
|
|
*/
|
|
|
|
if ( has_post_thumbnail() ) {
|
|
|
|
if ( $image[1] >= $header_image_width ) {
|
|
|
|
$thumbnail_size = 'large-feature';
|
|
|
|
} else {
|
|
|
|
$thumbnail_size = 'small-feature';
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
<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>
|
|
|
|
<?php
|
|
|
|
}
|
2011-06-11 07:07:18 +02:00
|
|
|
?>
|
|
|
|
<?php get_template_part( 'content', 'featured' ); ?>
|
|
|
|
</section>
|
2017-12-01 00:11:00 +01:00
|
|
|
<?php endwhile; ?>
|
2011-04-29 02:19:02 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
<?php
|
2011-05-10 00:54:55 +02:00
|
|
|
// Show slider only if we have more than one featured post.
|
2011-05-10 01:15:38 +02:00
|
|
|
if ( $featured->post_count > 1 ) :
|
2017-12-01 00:11:00 +01:00
|
|
|
?>
|
|
|
|
<nav class="feature-slider">
|
2011-04-29 02:19:02 +02:00
|
|
|
<ul>
|
|
|
|
<?php
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
// Reset the counter so that we end up with matching elements
|
|
|
|
$counter_slider = 0;
|
2011-04-29 02:19:02 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
// Begin from zero
|
|
|
|
rewind_posts();
|
|
|
|
|
|
|
|
// Let's roll again.
|
|
|
|
while ( $featured->have_posts() ) :
|
|
|
|
$featured->the_post();
|
|
|
|
$counter_slider++;
|
|
|
|
if ( 1 == $counter_slider ) {
|
|
|
|
$class = ' class="active"';
|
|
|
|
} else {
|
|
|
|
$class = '';
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
<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>
|
|
|
|
<?php endwhile; ?>
|
2011-04-29 02:19:02 +02:00
|
|
|
</ul>
|
2017-12-01 00:11:00 +01:00
|
|
|
</nav>
|
|
|
|
<?php endif; // End check for more than one sticky post. ?>
|
|
|
|
</div><!-- .featured-posts -->
|
|
|
|
<?php endif; // End check for published posts. ?>
|
2011-05-10 00:54:55 +02:00
|
|
|
<?php endif; // End check for sticky posts. ?>
|
2011-04-20 23:46:33 +02:00
|
|
|
|
|
|
|
<section class="recent-posts">
|
|
|
|
<h1 class="showcase-heading"><?php _e( 'Recent Posts', 'twentyeleven' ); ?></h1>
|
2011-04-26 20:34:52 +02:00
|
|
|
|
2011-04-20 23:46:33 +02:00
|
|
|
<?php
|
|
|
|
|
2011-04-29 02:19:02 +02:00
|
|
|
// Display our recent posts, showing full content for the very latest, ignoring Aside posts.
|
2011-04-20 23:46:33 +02:00
|
|
|
$recent_args = array(
|
2017-12-01 00:11:00 +01:00
|
|
|
'order' => 'DESC',
|
|
|
|
'post__not_in' => get_option( 'sticky_posts' ),
|
|
|
|
'tax_query' => array(
|
2011-04-20 23:46:33 +02:00
|
|
|
array(
|
|
|
|
'taxonomy' => 'post_format',
|
2017-12-01 00:11:00 +01:00
|
|
|
'terms' => array( 'post-format-aside', 'post-format-link', 'post-format-quote', 'post-format-status' ),
|
|
|
|
'field' => 'slug',
|
2011-04-20 23:46:33 +02:00
|
|
|
'operator' => 'NOT IN',
|
|
|
|
),
|
|
|
|
),
|
2011-06-10 22:14:59 +02:00
|
|
|
'no_found_rows' => true,
|
2011-04-20 23:46:33 +02:00
|
|
|
);
|
2011-06-11 07:07:18 +02:00
|
|
|
|
2011-04-29 02:19:02 +02:00
|
|
|
// Our new query for the Recent Posts section.
|
2011-06-11 05:44:42 +02:00
|
|
|
$recent = new WP_Query( $recent_args );
|
2011-04-26 20:34:52 +02:00
|
|
|
|
2011-06-11 07:07:18 +02:00
|
|
|
// The first Recent post is displayed normally
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( $recent->have_posts() ) :
|
|
|
|
$recent->the_post();
|
2011-06-11 07:07:18 +02:00
|
|
|
|
2011-04-29 02:19:02 +02:00
|
|
|
// Set $more to 0 in order to only get the first part of the post.
|
2011-04-20 23:46:33 +02:00
|
|
|
global $more;
|
2011-04-26 20:34:52 +02:00
|
|
|
$more = 0;
|
|
|
|
|
2011-06-11 07:07:18 +02:00
|
|
|
get_template_part( 'content', get_post_format() );
|
|
|
|
|
|
|
|
echo '<ol class="other-recent-posts">';
|
|
|
|
|
|
|
|
endif;
|
2011-04-26 20:34:52 +02:00
|
|
|
|
2011-06-11 07:07:18 +02:00
|
|
|
// For all other recent posts, just display the title and comment status.
|
2017-12-01 00:11:00 +01:00
|
|
|
while ( $recent->have_posts() ) :
|
|
|
|
$recent->the_post();
|
|
|
|
?>
|
2011-04-26 20:34:52 +02:00
|
|
|
|
2011-06-11 07:07:18 +02:00
|
|
|
<li class="entry-title">
|
2013-04-29 18:57:30 +02:00
|
|
|
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
|
2011-06-11 07:07:18 +02:00
|
|
|
<span class="comments-link">
|
2011-06-27 22:24:23 +02:00
|
|
|
<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentyeleven' ) . '</span>', __( '<b>1</b> Reply', 'twentyeleven' ), __( '<b>%</b> Replies', 'twentyeleven' ) ); ?>
|
2011-06-11 07:07:18 +02:00
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<?php
|
2011-04-20 23:46:33 +02:00
|
|
|
endwhile;
|
2011-04-26 20:34:52 +02:00
|
|
|
|
2011-06-11 07:07:18 +02:00
|
|
|
// If we had some posts, close the <ol>
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( $recent->post_count > 0 ) {
|
2011-06-11 07:07:18 +02:00
|
|
|
echo '</ol>';
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2011-06-11 07:07:18 +02:00
|
|
|
?>
|
2011-05-10 00:54:55 +02:00
|
|
|
</section><!-- .recent-posts -->
|
2011-04-26 20:34:52 +02:00
|
|
|
|
2011-04-20 23:46:33 +02:00
|
|
|
<div class="widget-area" role="complementary">
|
|
|
|
<?php if ( ! dynamic_sidebar( 'sidebar-2' ) ) : ?>
|
2011-04-26 20:34:52 +02:00
|
|
|
|
2011-04-20 23:46:33 +02:00
|
|
|
<?php
|
2017-12-01 00:11:00 +01:00
|
|
|
the_widget(
|
|
|
|
'Twenty_Eleven_Ephemera_Widget', '', array(
|
|
|
|
'before_title' => '<h3 class="widget-title">',
|
|
|
|
'after_title' => '</h3>',
|
|
|
|
)
|
|
|
|
);
|
2011-04-26 20:34:52 +02:00
|
|
|
?>
|
2011-04-20 23:46:33 +02:00
|
|
|
|
|
|
|
<?php endif; // end sidebar widget area ?>
|
|
|
|
</div><!-- .widget-area -->
|
|
|
|
|
|
|
|
</div><!-- #content -->
|
|
|
|
</div><!-- #primary -->
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
<?php get_footer(); ?>
|