WordPress Tip: Show the Latest Post in Full, Then Summaries of the Other Posts

Jane has wanted to implement something like Dooce’s Daily Chuck, where a new picture appears every day somewhere on the blog but not in the feed. The picture is usually just that — a picture, without much else. It works well to draw people to your site each day, knowing that you have something new.

For the past two weeks I’ve been trying to figure this out without much success. But I did come pretty close to achieving it. See the final effect here. And if you’re interested in the how-to, keep reading.

First, to get a better idea of how Dooce’s Daily Chuck works, go to her site and click the dog picture in the banner. It opens to a large image of the dog (“Chuck”), and you can click the Previous or Next links to navigate to the photos for the other days.

Dooce's Daily Chuck

Dooce's Daily Chuck

(By the way, I once met Heather at a book signing in SLC.)

Dooce is on Typepad, which may have some tricks that WordPress doesn’t. The easiest way to accomplish this same effect in WordPress is through the Post-Thumb plugin. (If you’re using Firefox 3, you may see a “Reported Attack Site!” message when going to the Post-Thumb plugin page. Instead, open the site in IE or go to the plugin’s page on WordPress.)

The Post-Thumb plugin scans your latest posts (of a specific category, if you want) and pulls out a thumbnail of the image with a link to the actual post. Perfect, right?

So I implemented it on Jane’s blog tonight and … down it went. I assume the Post-Thumb plugin initiated an intensive series of MySQL queries that triggered BlueHost’s extremely sensitive CPU Exceeded Error messages, and the site was down for a good 20 minutes.

CPU Exceeded Errors -- from BlueHost

CPU Exceeded Errors -- from BlueHost

By the way, the wp-supercache plugin seems to somewhat cure the CPU Exceeded Error messages, but I still think BlueHost has an abnormal amount of these error messages. If you google CPU Quota, most of the sites mention BlueHost. So perhaps the Post-Thumb plugin will work fine for you on a different host. If so, great.

There is, of course, more than one way to skin a cat. I’m still working on the way to show the latest thumbnail image in an RSS feed, but in the meantime, I found a neat little query script for the WordPress loop that shows the latest post in full, and then shows just the titles of posts after that.

The WordPress loop is the PHP script that calls the latest posts from the MySQL database. (Read more about the WordPress loop here.) The loop accepts various queries before it that control how the posts appear. (Read more about post queries here.)

Here’s the script (which I found here searching the WordPress support forums).

<?php if (have_posts()) : ?>
<?php $count = 0; ?>

<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>

<?php if ($count <= 2) : ?>

<h2><a class=”permalink” href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”>
<?php the_title(); ?></a></h2>

<?php the_content(); ?> // display the full content of the first two posts only

<?php else : ?>

<h2><a class=”permalink” href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”> <?php the_title(); ?></a></h2> // Just the permalinks

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

You have to massage the styles to fit your blog a bit.

The Subtle WordPress Theme has a similar feature hard-baked into the home page. But Jane didn’t want her home page like this, just a specific category.

Oh man, this is getting more complicated than I wanted to get into here. I was going for a 10 minute post, but ….

Jane wanted just one category to show the latest post like this. So I copied the category.php code into a text editor (Notepad ++), and then swapped the category’s loop with the above modified loop, and then inserted the styles of her theme to match. Here’s the resulting category code:

<?php if (have_posts()) : ?>
<?php $count = 0; ?>

<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>

<?php if ($count <= 1) : ?>

<h3><a class=”permalink” href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”>
<?php the_title(); ?></a></h3> <div style=”margin-top:-2px;”><small><?php the_time(‘m.d.y’); ?> <b>|</b> <?php the_category(‘, ‘) ?> | <?php comments_number(‘Comment?’, ’1 Comment’, ‘% Comments’ ) ?> </small></div><br/>

<?php the_content(); ?>

<b style=”size:2em;border-bottom: 1px solid black;”>Previous Entries</b>
<?php else : ?>
<h5><a class=”permalink” href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”> <?php the_title(); ?></a></h5>

<?php endif; ?>

<?php endwhile; ?>

<?php else : ?>

<?php endif; ?>

I then saved it as a new file, titling it category-87.php. Why category-87? Because when WordPress serves up a category view, it first looks for category templates for the specific category. If a category template exists, it uses that template rather than the regular category.php template. In this case, category 87 is ID for the Daily Dick and Jane category.

(By the way, to find the category ID, go to Manage > Categories. Move your mouse over the category title and look at the numbers at the far right of the string in the task bar. Nice, huh?)

I also needed to exclude category 87 from the home page. To do so, I added this query post code before the loop in the index.php file.

<?php
if (is_home()) {
query_posts(“cat=-87″);
}
?>

Now all posts in category 87 are excluded from the home page, but not the feed. I use Feedburner, so I just edited the feed details in Feedburner to exclude category 87.

I just changed the feed from

http://whataboutmomblog.com/wp-rss2.php

to the following:

http://whataboutmomblog.com/wp-rss2.php?cat=-87

And then I added some style to the h5 tag that wraps the previous titles.

Check it out by going to Jane’s blog and clicking Daily Dick and Jane. By the way, did you notice that she has 600 comments on her underwear giveaway post?

Madcap Flare Adobe Robohelp

This entry was posted in general, WordPress on by .

By Tom Johnson

I'm a technical writer working for The 41st Parameter in San Jose, California. I'm primarily interested in topics related to technical writing, such as visual communication (video tutorials, illustrations), findability (organization, information architecture), API documentation (code examples, programming), and web publishing (web platforms, interactivity) -- pretty much everything related to technical writing. If you're trying to keep up to date about the field of technical communication, subscribe to my blog either by RSS or by email. To learn more about me, see my About page. You can also contact me if you have questions.

28 thoughts on “WordPress Tip: Show the Latest Post in Full, Then Summaries of the Other Posts

  1. Erika

    Great little (or, well long) snippets!

    BlueHost is a nightmare, and thanks to their frequent screw-ups and incompetent customer service personnel, I advise anyone to stay away from them. Then again, nowadays… what hosting company couldn’t be characterized the same way? :(

    Erikas last blog post..Miami Web Design

  2. Kung Foodie

    Came across this while hunting for some WP hacks and just thought I would mention that Dooce is running on Druapl. Sje might have been using Typepad long ago but her husband now manages all the web development and has written about her Drupal install a few times.

    Kung Foodies last blog post..Moo Cow Cupcakes

  3. Online Loser

    You have saved me! I have checked in this site now a dozen times this week. I knew it was possible, but just did not know how. And chances of finding a useful answer in the WordPress forum are very small.
    Glad I found this site. I have used your code in several blogs now. My customers like the concept of a full last post and summeries of the rest.
    Can you also show me how to do this in the Archive.php
    I have tried implementing this code on the category pages, but seem to get error all the time.
    Thanks. I’ll be checking out the rest of your blog!

    Online Losers last blog post..Losing with your subconscious

  4. Tamara Jones

    Thank you for sharing those scripts. I have been having massive problems not only with Bluehost, but with the CPU excessive quota messages on some of the sites I want to work with. Because of this, it bogs down the time I spend on a specific site and/or task. I really appreciate what you posted and I’m going to add them to my plug-in. I hope this clears up some of these nasty hangups. Take care!

  5. Tom

    The WP-Supercache plugin has been doing a decent job of reducing the CPU excessive quota messages for me. However, that said, I still get them occasionally. Wish I never went with Bluehost. Transferring my sites and data is no small task, but someday I will. Hasn’t been much of a problem lately, though.

  6. Sheila

    I’ve been looking for a code/plugin for this forever.
    I’ve got the plugin into my wordpress (adminis. panel) where it’s supposed to be.

    But I’m confused still, so now let me ask this:
    Am I supposed to create a cat file like you did above for 87 (only mine is 12- FOR DAILY DOG)? To go along with this plug in?

    and question two:
    right now I have the big pain of manually cut/paste the permalink for the post AND the picture…up into the header/php for the little sized pic.
    I can’t even keep up with this, it’s a real pain.

    Is there some code I can paste up in there in the header so that the daily dog pic will automatically be pulled from the post? (Is that how the thumb plugin works?)

    I’m lost. Thanks, Sheila

    Sheilas last blog post..One reason for morning coffee

  7. Tom

    Sheila,

    Apart from using the thumbs plugin, I don’t know how to automatically pull thumbnails onto another page. I think the thumbs plugin is really the best method. However, when I implemented this plugin, it brought my site down due to the heavy pull on the database. I believe this may have been due to BlueHost’s sensitive CPU exceeded errors trigger. You can configure the thumbs plugin to pull only posts from a specific category.

    Yes, if I remember correctly, you create a cat-87.php file (or whatever your category is). Then include the code I added in the post. I’m not a PHP expert, so I rely on clips that I can pull together. Were you able to get anything working?

  8. Sheila

    Nope. I can’t get it to work like you were able to creating a new cat page. It didn’t pick it up at all, unless I was missing a code somewhere in order to be able to pick up the newly added cat page.?

    I’m fooling around with it again today. So I should be a basketcase by this evening! lol

    Sheilas last blog post..Elephant or Human?

  9. Sheila

    If I add this code (below) to my singlepost.php page, it puts in the next/previous links just fine. The only problem is I can’t figure out how to edit the code in order to do what your wife did on her daily page.

    I tried doing the separate cat page again like you did, and it’s still not working for me. Arghhhhh

    Sheilas last blog post..Elephant or Human?

  10. Sheila

    Okay, I just spent 4 hours on the wordpress codex. I’m not sure, but I’m thinking I need to:

    Create a new Theme file named category-319.php (which is my file in question’s #)

    Possibly copied from my next file in my themes that is in the heirarchy, which would be archives.php BUT modified somehow.

    Then I have to somehow link the new cat319 file to that catagory so that when that cat comes up or is clicked on, it will pull it’s info from the new cat319 file.
    WOULD I PLACE SOMETHING IN THE LOOP TO LINK?

    OR. Am I supposed to open a new php file in the FILE MANAGER (not my theme files)for Cat 319?

    Sheilas last blog post..Elephant or Human?

  11. Sheila

    Never mind. I think I figured it out. (cat-319) and the previous next code specific to the same categories.

    I just don’t understand how to make one category of posts look different from the singlepost.php.

    This just doesn’t seem to be possible.

    Sheilas last blog post..Rolling in Sweet Sweet Candy!

  12. Tom

    Sheila, did you ever get the theme file I sent you via email? Whenever I send you email I get an error message, so I’m not sure if you received any of them.

    Basically, if you name a file cat-319.php, when a user clicks that category archive, WordPress calls the cat-319.php file rather than category.php. This is known as template hierarchy, so if you search for Wordrpess Template hierarchy, you should find a lot of answers to your questions.

  13. Sheila

    My gosh, sorry it’s taken me so long to get back to you! I forgot where your site was because I was stupid and didn’t mark it! arghhhh

    Anyhow, no I didn’t get any emails nor anything in ‘junk’ although…my juno is weird. It’s not you, it’s me! lol.

    I worked through it for the most part and although it’s not working totally out like your example, I’m happy enough with it.

    My question now is…excluding a cat from the feedburner. I am wondering if by changing that code, (as in your example) then I would have to have everyone RE-SIGN UP for my feeds.??

    I found something people are saying is an alternative to changing the feed, and it goes in the functions file. Here’s the code:

    function myFeedExcluder($query) {
    if ($query->is_feed) {
    $query->set(‘cat’,’-431′);
    }
    return $query;
    }

    add_filter(‘pre_get_posts’,’myFeedExcluder’);

    I’m not sure if it’ll work. Have you ever heard of this working or is it just better to change the feed?

    Thanks for your patience! Sheila

  14. Sheila

    Oh for God’s sake, that code is only for WordPress Rss feeds. Ughhhhhhhh. Forget it, I’m just going to do what you said and have people resign up for my feed. Good heavens. I also provided you with an email address that won’t bounce anything.

  15. Cindy

    I’m trying to use the count feature to show 2 full posts then excerpts on my category pages. I just can’t seem to get it to pull 2 full posts, no matter what number I put in. Would the placement of `<?php if ($count ` make any difference? I have it above content but below title and date inside a div class. My date and title are below `

    `

    1. Cindy

      I actually found my issue…..I have a related posts section in the middle that also uses “count”, so it was breaking it. So I just changed this one to “loopcounter” in all instances and it works beautifully!

  16. MaMa

    Hello.
    Guide
    Attractions

    Tour Pattaya, Pattaya Nightlife
    Pattaya+Nightlife
    Bar, beer, entertainment disco, lady boys show cabaret pubs and live music outdoors at the famous Walking Street is known Nightlife.

  17. aran anusorn

    Pattay nightlife is very excited and vibrant. You can do fun at walking Street. Many casino and pubs are situated at Walking Street. It remain open entire night. Only need to find some condo to accommodate their. Condo for rent thailand is not easy to get as most of pre booked so I guess you have to do some online reservation for Thailand Condo.

Comments are closed.