definitely interested.

Stickies in Word Press

In various on November 27, 2006 at 3:55 pm

I think the real answer to my latest questions is “stop trying to make Word Press act like a full on CMS,” but while I’m stuck with it on a few projects, I figure I ought to share my cleverness with stickies. Here is my category.php template page–you’ll need a category called “sticky” to make this work, but you can show the first post that was categorized as “sticky” in each category overview page with this code.

Secretly, there is a plugin called “adhesive” that uses the custom fields to mark posts as sticky, but it wasn’t the easiest thing to find. It ought to be here, but it isn’t. If you rifle through enough forum threads, you’ll find out about Design Pastor, who posted a copy of it, for now. I wound up using the plug-in instead of troubleshooting this code.

<?php get_header(); ?>
<div id="content">

<?php if (have_posts()) : ?>
 	<h2 class="pagetitle"><?php echo single_cat_title(); ?></h2>

		<?php // first display the sticky post 	?>
		<?php  $sticky_query = new WP_Query('category_name=sticky&showposts=1');?>
		<?php while ($sticky_query->have_posts()) :
			$sticky_query->the_post();
			$do_not_duplicate = $post->ID; ?>
			<div class="sticky">
				<?php require('post.php'); ?>
			</div>
		<?php endwhile; ?>

	<?php // second, return to the loop ?>
	<?if (have_posts()) : while (have_posts()) : the_post();?>
		<?if ($post->ID == $do_not_duplicate) continue; ?>
		<?php require('post.php'); ?>
		<?php comments_template(); // Get wp-comments.php template ?>

	<?php endwhile; ?><?php endif; ?>
<?php else : ?>

	<h2 class="center">Not Found</h2>
	<p class="center">Sorry, but you are looking for something that isn't here.</p>
	<?php include (TEMPLATEPATH . "/searchform.php"); ?>

<?php endif; ?>

<h3 align="center"><?php previous_posts_link('Newer posts   ||   ') ?><?php next_posts_link('Older posts') ?></h3>
	</div> 

<?php get_sidebar(); ?>

<?php get_footer(); ?>
  1. I’ve tried using adhesive.php plugin but it messes up with paging. Have you overcome that problem? I am trying to use it in a 2.2 install.

  2. Hmm. I don’t remember even noticing an issue with paging. Sorry!

I don't have a comment policy, for better or for worse. If I really feel insulted by a comment I might take it down, but I'll always tell you why. I always flag cyrillic comments as spam even though I can't read them so technically I have no idea what they're about. I apologize for that business about comments being a "privilege" -- my penance for using a template out of the box. Rest assured that it is my privilege to have you here!