Custom Post Type Archives in WordPress 3.1

When I released Prospress last year, it used a contrived system for creating an index of auctions.

This was necessary as WordPress provided no standard method for creating an index page for custom post types. Now that 3.1 is just around the corner, this is all about to change.

Creating a Custom Post Type Archive

Let’s get semantics out-of-the-way first. It may be called an archive, for reasons hotly debated, but an archive can act as an index for your post type, just like the index.php file for blog posts.

Now, let’s take a look at the two simple steps for using a custom post type archive.

Step 1: Add an Archive Template to your Theme’s Folder

Create a new template to act as your custom post type’s archive. You can use any markup or style in your template. I start by copying the theme’s existing index.php file and then add any additional template tags or make any style changes from there.

You must name your template archive-{post-type}.php and store it in the base of your theme’s directory. For example, the auctions archive for Prospress is archive-auctions.php.

You only need to use a standard loop in the template. No need to run a new query for your custom post type – WordPress takes care of all that.

Step 2: Tell WordPress Your Post Type has an Archive

Now we have our template, we need to tell WordPress we want it to use a custom archive.

When registering your post type, set the has_archive flag in the $args array to true. This tells WordPress to generate the rewrite rules for your post type’s archive page.

For Prospress, this looks like so (abridged & paraphrased):

$args = array(
		'public' 	=> true,
		'rewrite' 	=> array( 'slug' => 'auctions' ),
		'has_archive' => true,
		);
	register_post_type( 'auctions', $args );
}
add_action( 'init', 'register_auction_post_type' );

WordPress will now attempt to load archive-auctions.php for requests of the url example.com/auctions/.

A question on WordPress Answers also hints you can set the value of has_archive to create a custom rewrite instead of simply using true/false. I haven’t tested this though.

There you have it, a custom post type index or archive template. Told you it’s simple.

For further reading, check out:

Posted in Blogdex, WordPress | Tagged , , | 5 Comments

The Limits of Anonymity

On the back of yesterday’s post about Anonymous Blogging, Ryan Markel has posted about the Limits of Anonymity on WordPress.com.

He mentions the WordPress.com privacy policy:

We keep the following private data about WordPress.com sites and users:

  • The email address used to create a blog
  • The IP address from which the blog was created
  • The date and time when a blog was created
  • The IP addresses from which blog posts have been published
  • The email and IP addresses of anyone who has left a comment on a blog

I’ve got to say, those are surprisingly trivial limits. I’m impressed by just how little private data Automattic is keeping.

Yet another instance of Automattic doing what seems good for customers before what’s good for the bottom line. This strategy appears to be paying off though. WordPress.com grew by 6 million new blogs in 2010 and had a 53% increase in pageviews.

Posted in Navel Gazing | Tagged , , , | Comments Off on The Limits of Anonymity

Anonymity in Blogging

A friend just sent me a link to his blog. He’s been writing wildly candid stories for more than a year – all under the thin veil of anonymity.

It’s clear from his writing that anonymity affords him a great freedom – the freedom from pressure. No pressure to impress. No pressure to self-serve. No pressure to be consistent.

This freedom improves how his writing flows. His stories don’t feel contrived in the slightest. It’s rare to see a non-anonymous blog that flows so freely. To be sure, they exist, and that’s what makes a great blog. But it’s rare.

So despite also being a bit of an experiment in free-form blogging, this post kind of begs the question, can anonymity improve blogging?

To be sure, anonymity can lead to fuckwadism. But I see great value in it, as least for those first few steps into the deeply open world of the web.

Posted in Navel Gazing | Tagged | Comments Off on Anonymity in Blogging

How to Insert a Tick into a Google Spreadsheet

Want to insert a tick mark, like this ✓, into a Google Spreadsheet?

It’s easy, just copy this tick ✓ and paste it into a cell. Or if you’d prefer it heavy, copy this check mark ✔.

Sometimes such simple things can be deceptively difficult. I hope this helps others.

Posted in Blogdex | Tagged , , , | 24 Comments

Google Analytics Broken in DotNetNuke 5.6

If you suffer the cruel affliction of a DotNetNuke website, you may find your Google Analytics charts flat lined around November or December of 2010. DotNetNuke 5.6 introduced a bug in the analytics code, fortunately, the guys from Interactive Webs have published a solution.

Google Analytics Broken in DotNetNuke

Google Analytics Flatlining

Posted in Blogdex | Tagged , | Comments Off on Google Analytics Broken in DotNetNuke 5.6

Choose Your Own Adventure

A company sold one of its web properties two weeks ago for $90 million. That normally wouldn’t concern me, except that same week, they launched the world’s first site to implement an idea I’m also working on.

Whenever I conceive a half-way decent idea, I try to assume there are smarter people with better capacity working on it. It’s still scary when you find that assumption is correct.

You discover you’re second past the post and competing with a company that has circa $100 million in the bank, what do you do next:

  1. persist
  2. give up
  3. get as much critical feedback as possible then rework the idea
  4. a & c.

I’ll take d.

Posted in Hacker Tales | Comments Off on Choose Your Own Adventure