WordPress TwentyEleven Theme – Show Only Sticky Posts In Home Page

Introduction

As part of the customization of my site, I want to display only sticky posts on the home page.  On the average I expect to have one sticky post at the time.  This post documents how to modify the TwentyEleven Theme in WordPress 3.2 to achieve this functionality.

Implementation

Visit ThemeFm for a good overview of the TwentyEleven theme. This is really a one liner.  Open the index.php template, and insert the <?php if(!is_sticky() && (is_home() || is_front_page()) ) break;  ?> line just before the get_template_part(…) call.

<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php if(!is_sticky() &amp;amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp;amp; (is_home() || is_front_page()) ) break;  ?>
<?php get_template_part( 'content', get_post_format() ); ?>

This line of code check if the post is not sticky and the home or front page is being display.  If this condition is met it aborts the loop.  This works because WordPress displays all sticky posts first.  That’s it we are done.

Print Friendly, PDF & Email

WordPress TwentyEleven Theme – Taming Category And Archive

Introduction

I am a new to WordPress.  My site is running WordPress 3.2 with the TwentyEleven theme.  I wanted to change the way posts under archives and categories are displayed.  Instead of listing all the posts, I want to list the title of the post and a summary.  This post describes the simple changes that need to be done to the TwentyEleven theme to accomplish this change in functionality.

Implementation

Visit ThemeFm for a good overview of the TwentyEleven theme.  The content.php page, which is the page with the default template to display all post, has logic to display the summary of the post when it is displayed in a search.  That’s exactly what I want to do when displaying the list of posts in a category or in an archive.  Step 1, is to make a copy of the content.php template and to name it content-archive.php.
Step 2, requires minor modifications to the content-archive.php page.  Look for the following code in the content-archive.php.

?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div>
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div>
<?php the_content( __( 'Continue reading <span>&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;rarr;</span>', 'twentyeleven' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php endif; ?>

Replace this block of code for the following code in order to force the the template to behave as in search mode.

<?php // display Excerpts for archive ?>
<div>
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->

At this point we have a template that displays the title of the post with date information and the summary.  Step 3, requires linking the content-archive template to the archive and category display.  Open the Category Template (category.php) and replace the following code

get_template_part( 'content', get_post_format() );

with the following line in order to link the content-archive to the category display.

get_template_part( 'content', 'archive' );

Repeat the same step for the Archive Template (archive.php) and that’s it, you are done.  Settings->Reading allows you to control how many posts to list per page.

Print Friendly, PDF & Email