how to show an excerpt from the first post in a category in wordpress

For ReadComics.org I wanted to show the latest Book Club entry in the sidebar. For those of you who are not familiar with the way WordPress does its posts, it uses some funky wrapper functions to access (and sometimes print) the entries in your blog. The main wrapper function, and the one that controls most of the stuff on the page is called the_loop().

This might be getting too detailed… You probably just want to know how to do what I did. There’s a lot more details on wordpress.org about using multiple loops on one page, but basically, the technique I used was to specify a new loop by using one of its internal functions called WP_Query directly.

WP_Query() takes an argument that tells it to just get the latest post from the book-club category. That looked like this: <?php $bc_query = new WP_Query('category_name=book-club&showposts=1'); ?> This uses category slug (“book-club” in my case), which you can find by editing your category.

So then you can use the standard functions like the_title() and the_excerpt() in a while loop. So the whole thing looks like this:


<li><h2>Next Comic Book Book Club</h2>
<!-- Get the last post in the book-club category. -->
<?php $bc_query = new WP_Query('category_name=book-club&showposts=1'); ?>
<?php while ($bc_query->have_posts()) : $bc_query->the_post(); ?>
<a href="<?php the_permalink(); ?>" alt="Read more about the next book club meeting." title="Read more about the next book club meeting."><?php the_excerpt(); ?></a>
<?php endwhile;?>
</li>

…and yes, I know the_excerpt() creates paragraph tags, and anchor tags around paragraph tags probably doesn’t validate. Oh well.

whats up w/ me

I can’t believe I didn’t write on here at all in June. Check out ReadComics for some of what I’ve been up to, but other than Wizard World, Convergence, and Peter’s visit last week, things have been pretty stable and steady. Oh, I guess the new apartment counts for something also.

I’m trying to get back into drawing… (this is going so-so… I’m not being very serious about it) and trying to exercise more often… blah blah blah…

brief (but gentle) iPhone tirade

I saw a post somewhere (too lazy to even dig up the link again) with their pie in the sky iPhone wishlist. And I figured, while I’m thinking about it, and while I’m waiting for the iPhone-devteam to get around to releasing the software that will let me upgrade to 2.0 (cause I can’t be bothered without the jailbreak), I figured I’d blort out a quick post about what I wish I had on the iPhone.

  • copy/paste — This is self-explanatory, and I don’t know a single iphone user who hasn’t bemoaned this lack from the beginning. I personally love the way tap-select (and two-tap-right-click) works on the new powerbook touchpads, and wish they’d just get around to implementing it, for crying out loud.
  • bluetooth keyboard support — This also seems like a no-brainer. I want to be able to use the iPhone for writing on the go. Not to mention using ssh in any sort of realistic fashion. ;)
  • multi-machine music add — With my iPod, I can add music from the various machines I’ve “authorized” to use my iTunes account. Why can’t I do this with my iPhone!?! It’s SO frustrating. I have hardly any space left on my home machine, and I didn’t even have my work machine when I got the iPhone initially.

I guess that’s it. I can’t wait to have (access to) a G3, so I can use the GPS features, but honestly, other than increased speed on the go, I can’t imagine much else that could be better about it.