Filed Under: Coding, Snippets, Websites
I really like the idea of Mini-Posts on blogs. I’m a regular reader of Matt’s blog and he uses mini-posts all the time. Nope, there’s no plugin involved, nor any PHP-file edits needed. Just a few template changes. Below I’ll show you how to implement mini-posts for your own blog.
Step One
First, you need to make a category for your mini-posts. On JordanH.net, the category is called Mini-Posts. Any mini-posts you make need to be posted in this category. Remember the ID number of the category - you will need it in the next step.
Step Two
Now, open up the Main Index Template file and then add this code just at the beginning of the loop. Remember to substitute the category ID number in the highlighted place:
<?php if (in_category(CATEGORY_ID) && !$single) { ?>
<div class="entry"><div class="post" id="post-<?php the_ID(); ?>">
<?php echo $wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id");
echo ' '; comments_popup_link('(0)', '(1)', '(%)')?> <?php edit_post_link('(e)'); ?></div></div>
<?php } else { ?>
Before the close of the loop, add a ending brace.
Now replace the CATEGORY_ID with your category ID from earlier. You may want to adapt the template changes to reflect your template classes etc. The reason we use an SQL query to get the contents of the post, is to stop WordPress automatically adding paragraph tags around the post text (which is good for normal posts, but adds extra whitespace on mini-posts).
Step Three
Now try posting a post in the category, and it should show up on your blog as a mini post. It still has the comments/permalink functionality, try clicking the (0) link next to the post to view all the comments and the permalink. These will also show up in your RSS Feed.
Hope this helps! If anybody has a way of doing this more easily (especially the SQL query, is there a function for that?), leave a comment!
Subscribe to comments feed (this is global, not just for this entry)