Have you ever tried to insert advertisements (or any bit of code really) into the WordPress post loop, then found that it will insert the banner after each post? It really depends on what you are going for, but this usually will not be an ideal solution to placing advertisements between posts on your homepage. If you’d like to place something only after the first post in the WordPress post loop, here is a quick hack you can do to tell WordPress to only display it after the first post.
Simply go to your themes homepage and look for the following code:
<?php endwhile; ?>
Immediately before this code, place the following code:
<?php if(!$show_ads){ ?>
Insert Code Here
<?php $show_ads = 1; } ?>
Obviously you’ll want to replace Insert Code Here with your code. Told you it was easy!
Possibly my favorite feature introduced in WordPress 2.6 was the wiki-style document revisions. You can now easily get access and/or restore old revisions. It took a few days to get used to, but I have to say I really love it!
I’ve always felt that this feature was intended primarily for multi-author blogs and probably isn’t needed for most WordPress bloggers, as it only serves to grow your wp_posts database table. If you are someone that would like to disable this feature, all you need to do is open your wp-config.php file and add the following code:
define('WP_POST_REVISIONS', false);
This should restore WordPress to handling posts the way it did in the WordPress 2.5 branch and earlier!
In my opinion, all blogs should have an archive page: It allows your readers to quickly browse your blog and find what they’re looking for, and this page is also very good for SEO.
Here’s how to create this page on a Wordpress blog:
Archive Wordpress Plugins
There’s many plugins which allows you to automatically create an archive page. The good thing is that you’ll have (almost) nothing to do, and the bad thing is that you will not be able to customize it a lot, or you’ll have to edit the plugin files, which is sometimes a bit too hard if you’re not a developer.
On my blog in French lyxia.org, I use the Smart Archives plugin. Even if it gives me satisfaction, the loading time of the page is very long due to the amount of posts to be displayed simultaneously.
If you want to use a plugin, you shall also give a try to Clean Archives, or Extended Live Archives, which allows numerous personalizations.
Do it yourself
Wordpress allows you to create page templates, so it’s possible to create manually an archive page. This is what I chose to do on my blog in English, CatsWhoCode.com.
Before starting to code, you’ll have to choose between two different kinds of archive page. The first one will list all your posts, and will allow a direct access to every article you wrote. The only bad thing is that when your blog will have many posts, the list may be a bit too long.
The second template, which is better for blogs that have been online since more than one year, will list your posts monthly and by categories.
Your choice is made? So let’s go coding!
First we’ll have to create a new file and name it archives.php. At the beginning of the file, paste the following lines:
<?php /* Template Name: Archive page */ ?>
This php comment define a name for our template, and will later allows us to select it on Wordpress Dashboard, when we’ll create a new page.
First template: Listing all posts
<?php
$posts_to_show = 100; //Max number of articles to display
$debut = 0; //The first article to be displayed
?>
<?php while(have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<ul>
<?php
$myposts = get_posts('numberposts=$posts_to_show&offset=$debut');
foreach($myposts as $post) :
?>
<li><?php the_time('d/m/y') ?>: <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php endwhile; ?>
Second template: Archives by months and categories
<?php while(have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<h2>Monthly archives</h2>
<ul><?php wp_list_cats('sort_column=name&optioncount=1') ?></ul>
<h2>Categories</h2>
<ul><?php wp_get_archives('type=monthly&show_post_count=1') ?></ul>
<?php endwhile; ?>
After you chose one of the templates I shown you above and pasted it to your archives.php file, you just have to upload it on your wp-content/theme/yourtheme/ directory.
Then, in Wordpress dashboard, create a new page, name it “Archives” (or whatever you want) and select Archive page as page template.
That’s all! You now have an archive page, which is good for both your reader and search engines crawlers.
Here are a few WordPress-related links I’ve enjoyed over the past few weeks:
- How To Display Code in WordPress Posts - Leland of Theme Lab has posted some tips/plugins you can use to help you display code in your WordPress posts.
- 40+ WordPress Tricks and Hacks - Hongkiat has another good collection of WordPress hacks and other guides, including a few of ours.
- WordPress 2.6 Disabling XML-RPC By Default? - James Mowery of Performancing takes a look at the effects of WordPress 2.6 coming with XML-RPC disabled by default, which will hopefully reduce security risks. Unfortunately, this will also pose a problem for people that write their posts in 3rd party blogging software such as Windows Live Writer and will have to be manually enabled.
- 20+ Must Have WordPress 2.5 Compatible Plugins - Mashable has posted over 20 WordPress plugins that are compatible with WordPress 2.5.
At the time when Hack WordPress was created close to a year ago, there were only two sites that were completely dedicated to WordPress (Weblog Tools Collection and Lorelle on WordPress), and both focused a lot of their time covering WordPress news and the community that surrounds it.
The original intention when building this site was to feature a number of WordPress hacks, tips, and/or how-to guides each week to kind of fill the gaps and provide resources for WordPress users. Over time, I feel this site has branched out to become much more, but the core of this site is still focused on providing WordPress theme hacks. In addition to the ones I’ve written, we’ve also had some great hacks contributed from a number of different WordPress enthusiasts.
Because I felt that our archives are not as focused as was originally intended, I have decided to create a place to strictly collect links to our posts providing WordPress hacks, WordPress tips, and WordPress guides. This will replace the Archives link in our menu.
There are a number of new WordPress hacks planned for the future, so the plan is to update this post every time a new hack is published!
Theme Hacks
- How to Add Widget Support to Your WordPress Theme
- How to Prevent WordPress Plugins From Breaking Your Blog
- How to Add Edit Buttons To Your Theme
- How to Add WordPress Tags to Your Theme
- How to Setup RSS Feed Auto Discovery
- How to Use WordPress Conditional Tags
- How to Hide Your Subcategories (Children)
- How to Prevent Google From Indexing Your Images
- How to Create a Two-Tiered Navigation Menu
- How to Make WordPress Function Like a CMS
- How to Add a Print Button To Your Theme
- How to Add an Email Button To Your Theme
Stylesheet Hacks
Post Hacks
- How to Add Daily Blog Posting via Del.icio.us
- How to Convert Your Author Links to Point Towards the Authors Site
- How to Show Only a Post Excerpt
- How to Display a Last Modified Date on Your Posts
- How to Add Bio Information to Your Blog Posts
- How to Alternate Post Background Colors
- How to Add Author Gravatars to Authors Posts
Comment Hacks
- How To Separate Comments and Trackbacks
- How To Single Out Author Comments
- How To Add Numbers To Your Blog Comments
- How to Display Recent Comments First
Page Hacks
- How to Create a Custom Page Template
- How to Hide Individual WordPress Pages
- How to Add an Author Page To Your Theme
- How to Optimize Your 404 Error Page
Categories/Archives Hacks
- How to Limit How Many Archives are Displayed
- How to Remove Ads from Select Categories
- How to Display Recent Posts for Specific Categories
- How to Change the Author Archives Permalink
- How to Convert Your Categories to Display Post Titles
Blogroll Hacks
If you deal with WordPress template tags, I just ran across an incredible new WordPress resource. It is called the WordPress Template Tags Reference Guide, and is basically a reformatted version of WordPress.org Codex page for template tags.
If you deal with template tags regularly, I would definitely recommend booking this page. I have added this to our WordPress Resources page.











