WordPress 3.0 Sticky Post Loop Structure

How To Modify WordPress' Sticky Post LoopRecently, while working on a client website, I wanted to utilize WordPress’ “Sticky” post function. This option has been around since version 2.7 (went unnoticed by me until now) and is located under the publishing options (see image).

PHP experts, please ignore my n00bness, this post is not for you. This is for folks who aren’t strong in hand-coding PHP, but somewhat grasp “the loop”.
I’m a front-end developer & designer who tries to dabble as much as possible in PHP and JS. I’ll probably never fully grasp PHP, simply because I’m not sure my brain works that way. Time will tell.

The Problem

By default, the “Sticky” post seems to pull-in the regular “index” loop assets via loop.php. I wanted to control the way the sticky post was called-in and could not find documen­tation or any relevant articles on the googles. I wanted the sticky post to act more as a “welcome message” than as a full post. This would involve re-structuring the loop.

By default, the Sticky Post loop pulls-in:

  • the title (linked to full article)
  • the meta data
  • the excerpt or the content.

I only wanted to pull-in:

  • the title (unlinked)
  • the content
  • edit post link

My Solution

For this example I’m refer­encing the default loop.php included with WordPress’ Twenty Ten theme — which calls-in three different loops based on specific parameters.

In the “loop.php” file, simply add in the following at the start of the loop (directly after the large commented area “Start the loop”) :

<?php while ( have_posts() ) : the_post(); ?>
<?php /* Sticky post loop structure. */ ?>
	<?php if ( is_sticky() ) : ?>
		<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                       /* sample loop */
			<h1><?php the_title(); ?></h1>
				<?php the_content(); ?>
			<?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>

		</div><!-- #post-## -->

Hopefully someone else will find this post helpful. I’m aware it’s a simple statement, but it was fun to play around with and figure out. I plan on modifying and utilizing my own sticky posts someday soon. I’m happy WordPress added the function to the core.

This entry was posted in Design and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>