A couple of gifts for you

As this year draws to a close, your friends here at Sillyness would like to give you a couple of gifts.

When I moved from my previous design 'Fresh and Clean' I had decided to package it up as best I could and release it as a free theme for WordPress.  Today that dream becomes a reality.

Also, as many of you know, I had been working on a new theme for Sillyness code named 'Believe'.  As I have stated elsewhere I came to realize that I have shifted artistically back to the world of paint and charcoal; I gave up on my new design, and you guessed it, decided to package what I had up and release it as well.

Read the rest »

 

Post a job. Find one. authenticjobs.com

 

K2 for WordPress

K2 is a WordPress modification—an advanced template—created by Michael Heilemann and myself, created as an improved Kubrick of sorts. It won't make you coffee, sing songs of sweet regret or sit at your bedside when you're ill, but it might make life just a tad bit easier for you.

It was built to make it an easy foundation for others to base their work on. And because it's free and open source, well you can do pretty much anything you want with it. So feel free to steal whatever you need from it and throw away the rest.

For more information, a demo and the download head on over to Mike's K2 page.

 

Secrets of WP Themeing: The Complete Series

Here is my complete series on Themeing With WordPress 1.5 collected all in one place for your convenience.

Part 1: originally posted here

So lets talk about Custom Templates, and more importantly how we can bend them to our will. Now I am assuming that by now everyone has at least a passing familiarity with Templates in WP 1.5, for those who are not up-to-speed, lets cover some back-story.

In the beginning were Templates, and lo they were good.

Templates are the foundation of the WP theme system, and one of the most powerful features, in my opinion, in 1.5. A template defines the layout and “feel” of different aspects of your WP powered site.

There are a number of templates that are strictly defined in WP, they are as follows (list taken from the codex):

  1. style.css
  2. index.php
  3. comments.php
  4. comments-popup.php
  5. home.php
  6. single.php
  7. page.php
  8. category.php
  9. author.php
  10. date.php
  11. archive.php
  12. search.php
  13. 404.php

For instance, I have a template that defines the look of my index, one that defines viewing single posts and one for category listings. Each one has different structure, CSS and WP function calls based on its purpose. The one thing they all have in common is the_loop, or the bit of code that tells WP to spit out the appropriate posts for a specific area of my site.

So class, are we all caught up on templates? Good, well what happens when we want to add a page to our site that doesn’t have anything to do with our posts or categories?

Say we want to add an archives page like the one here at Sillyness to our sites?

Again we turn to Templates, more specifically Custom Templates.

Templates, Posts, Pages and Plugins

Now we have already stated that there are a number of strictly defined templates in WP. But there is also another category of templates, ones that can be anything, can be called anything and can be applied to any “Page” you create in WP. It is here with Custom Templates that the fun begins.

It is a little known fact that you can apply custom templates to blank “Pages” in WP. What I mean is that you can create a completely blank page in WordPress and then apply a custom theme laden with code to it. As an example lets look at the archives page here at Sillyness.

If you were to look at the page I created in WP named Silly Archives, the “Page Content” area would be completely blank. If you then opened my custom template you would see a whole mess o’ code, and interestingly enough the_loop is no where to be found. In fact the only WP core code that you would find would be get_header(); and get_footer();

The rest is either embedded code, or plugin calls.

So let’s get into some code.

So back to our hypothetical example. Our first step would be to create the custom template that will be applied to our Archives page. Because we do not re-invent the wheel, we will be making use of Shawn Grimes Clean Archives plugin, and my Commenter Heat Map plugin.

So first things first, every custom template must start with the following code:

/*
Template Name: Archives Template
Description: A template for my archives pages.
*/
?>

In addition for this particular page we need to add a call to wp-blog-header.php so our opening code will actually look like this:

require('./wp-blog-header.php');
/*
Template Name: Archives Template
Description: A template for my archives pages.
*/
?>

Next we call for our header.php file and start adding our content:

<?php get_header(); ?><div class="main"><h2>Here are the archives for <?php bloginfo('name'); ?>.
</h2><p>Search the archives.
</p><div class="search"><form method="get" id="searchform" action="/index.php"><input type="search" value="Search" name="search" id="s" /><input type="submit" id="submit" name="Submit" value="Go!" /></form></div>

Now you could have put some of this in the “Page Content” area of the ‘Create Page’ screen, but for this demo we want to have everything in the template, so on we go.

<?php echo srg_clean_archives(); ?><h2>Commenter Heat Map
<h2><p>Below is a heat map of the commenters here.
<p><?php cjd_comment_heat(); ?></div>

And finally we close with the footer call:

<?php get_footer(); ?>

And that is the entire template, now we save it as new_archive.php and upload it to our /wp-content/themes/ourtheme/ folder, then log into our WP admin area to create a new Page.

Lastly we need to create a blank Page and link it up with our new template.

So let’s go to Write > Write Page and get to business. First off we need to give our page a title, let’s say My Archives, once that is done we can skip down past the “Page Content” area to “Page Options”.

The first field should be Page Template, and in the drop down box we should find Archives Template, select that and click Create New Page. That’s it, if you have installed and activated the plugins, when you load http://my.site/my-archives/ you should see your lovely new Archives page.

Well that’s it for the first of this series. I hope you have had as much fun as I have. If you have any questions, leave them here in the comments and I will do my best to answer them.

Part 2: originally posted here

When last we met we talked about Using custom templates to add pages to WP that don’t necessarily call for posts or categories, etc. Today we continue our exploration of custom templates by looking at another little known power hidden within the theme system: Per Category templates.

Hidden Spiffiness abounds

Deep within the recesses of the WordPress code base lies dormant the power to create custom templates for each of your categories, what is even more astounding is how easy it is to pull off. This sleeping giant merely awaits the correct file names and it will wake unleashing untold shininess and spiffiness upon your visitors heads!

It should be said that this isn’t a feature that we are all going to want to run out and use, but I think that for a select few this will be a a breath of fresh air, not to mention a solution to many frustrations.

When you get down to brass tacks, this is a profoundly easy feature to exploit. All you need to know is the number of each category and you know, what you want each one to look like. So lets look at how I am using this feature here on Sillyness.

Context sensitive information is the bees knees

I am a big believer in giving information to the user that is both contextually correct and also useful. A prime opportunity for this is when a reader is browsing your category pages.

Here on Sillyness where appropriate you will find in the left aligned column a list of “other resources” specific to the category you are browsing. Two prime examples are the Tutorial and Web Standards categories. On each one you will find links to offsite resources.

Now this is a very limited example of per category templates. If you wanted you could change every aspect of the way the page is displayed, load alternate style-sheets anything… the sky is the limit. But think before you go crazy people.

So what does one need to do to tap into the power of per category templates? Glad you asked!

So lets write some code, shall we?

After the previous discussion, creating these templates will be a piece of cake. First of all lets start off by making sure we actually have a category.php file to begin with. I find it very helpful to have a good layout with which to browse categories, and you readers will too.

So let’s say we are all brilliant and already have a category template file, we need to open that puppy up in an editor and decide what we want to customize for lets say… the gorilla category. Heh, gorillas are funny.

Okay so we are going to create a template for our gorillas category (cat number 18).. okay? Good. So I think we need to have some links to gorilla resources on the net offered to our visitors while they are in our gorilla category listing, don’t you?

So lets get to tinkering , first we throw out an oldy but a goody:

<?php
require('./wp-blog-header.php');
/*
Template Name: Gorilla Category Template
Description: A template for the Gorilla Category.
*/
?>

Next we call for our header.php file and start adding our context specific info:

<?php get_header(); ?><div class="main">

Now usually we would want to just call and include the template file sidebar.php, but we are wanting to add that context info and the menu is the best place for it. So we will be hardcoding this bit on each template.

<div class="menu"><ol><li><a href="http://gorilla.com" title="gorillas">gorilla.com</li><li><a href="http://jungle.com" title="Home of gorillas">Jungle.com</li><li><a href="http://kong.com" title="really big gorilla">Kong.com</li></ol></div>

Then we go on and throw out the template tags that tell WordPress how we want to display our listing on the category page:

<div class="main"><?php if (have_posts()) : while (have_posts()) : the_post(); ?><h4><?php the_time('') ?></4><h1><a href="<?php echo the_permalink(); ?>"> <?php the_title(); ?></h1><h3><?php the_category(' ,'); ?></h3><?php the_excerpt(); ?><?php endwhile; else: ?><p><?php _e('Sorry, no posts matched your criteria.'); ?></p><?php endif; ?><div class="right2"><?php posts_nav_link('','','Next Page »') ?><br /><?php posts_nav_link('','« Previous Page','') ?></div>

And finally we close with the footer call:

<?php get_footer(); ?>

Now for the payoff, making it all work

Okay, so now we have created a template for our gorilla category, complete with spiffy links about gorillas for our readers. Now we are ready to save this bad-boy, but how does WP know to use this when gorilla is called?

Now it is time to do something with that category number we found. All you need to do is save this file as category-n.php where n is the number of your category. So since gorilla is cat number 18 we would save this file as category-18.php and upload it to our wp-content/themes/mytheme/ directory.

Easy-peasy as they say. Believe it or not, that is all there is to it. The next time you load the gorilla category you should see the template we just created.

Well that’s it for this installment of the series. I hope you have had as much fun as I have. If you have any questions, leave them here in the comments and I will do my best to answer them.

Part 3: originally posted here

Well it is time again for everyones favorite series. So far we have covered some pretty groovy stuff. Part 1 showed us how to create custom code laden templates that can be applied to blank pages in WP to achieve some gnarly effects.

In Part 2 we talked about creating custom templates for each of your categories, opening up a whole world of possibilities. Today we are going to talk about a little used theme template, the Home Template (home.php).

There’s no place like Home

So as you remember we talked about the different files that WordPress is hard-coded to recognize. One of these that we have not talked about yet is home.php. This template file is only used when index.php is called without any arguments passed to it.

That is a mouthful, isn’t it? What that nonsense above means is the following. When you load this site, the physical URI, or address is http://chrisjdavis.org/index.php, and when you click on a link to a specific post, say this one which is number 732, the address becomes index.php?p=732. Now p=732 is an argument, or rather how we tell WP that we want to see post #732.

My site uses some mod_rewrite magic so you dont see that, but trust me it is there, so home.php is only used when the physical address in the address bar of our browser is somesite.com/index.php.

And that matters to me WHY exactly?

Good question, glad you asked.

First, time for a little demonstration, take a moment and head on over to my test site and look around. Back now? Good. So what do we see over there? Well the top row contains images from my Flickr account, the second row features the latest 5 posts from The Test Bed and finally the last row contains the last 5 entries from my Support Forums. The index page has become more of an overview page, and you know the best part… I haven’t called the WordPress loop: anywhere on that page.

Now what I am about to show you isn’t neccesarily the best way to go about this, I am merely choosing this course of action to demonstrate how powerful and completely disconnected from the core function of WP you can make home.php. Keep that in mind.

So how am I displaying all this info if I am not hitting the database for it?

Simple, I am using the WordPress version of magpieRSS to grab, parse and style various RSS feeds.

What home.php gives you is the ability to have a WP handled index page that can be more static in nature, with a blog behind the scenes. In essence we move closer to using WP as a Content Management System, as opposed to merely an elegant blogging platform.

Now of course you would want to have the_loop included in the home template to simplify matters, I just wanted to get across the extreme flexability of WP when using templates by going without it.

So lets write some code

Now for most of you this will probably be your first exposure to the RSS aggregation built into WP, don’t go nuts with it! It is powerful and easy to use, but you take a hit in performance when using it.

So we open up with the customary code:

<?php get_header(); ?>

Here is our first new bit, we need to call the rss functions and set a variable to todays date:

<?php require_once (ABSPATH . WPINC . '/rss-functions.php'); ?><?php $today = current_time('mysql', 1); ?><div class="main"><h2>Recent Flickr
</h2>

Now I am not parsing RSS for the Flickr area, since they (Flickr) provide a nice little solution for this already. I am not going to paste it all in here, but you can find the code easily enough if you are a Flickr user.

Okay here is where the fun begins, we are now ready to call and handle the first RSS feed.

<?php
$rss = @fetch_rss('http://chrisjdavis.org/testbed/feed/');
if ( isset($rss->items) && 0 != count($rss->items) ) {
?>

So what have we done so far? We are telling WP that we want to grab the RSS feed from this site, and if the feed responds, then move on.

<h3>Latest Posts on </h3><ol><?php
$rss->items = array_slice($rss->items, 0, 5);
foreach ($rss->items as $item ) {
?>

Okay the above snippet of code is saying, grab the pieces of the RSS feed, publishdate, author, title, content etc and create an array from them, and then for each of these arrays returned do what comes next.

<li><a href=''><?php echo wp_specialchars($item['title']); ?>
<?php echo human_time_diff( strtotime($item[’pubdate’], time() ) ); ?><?php _e(’ago’); ?>
</li><?php
}
}
?></ol>

Okay, lets look at what is going on here. First we are grabbing the link for the item returned and passing it through one of WP’s many filters. This link will allow us to load the post in full at the site referenced. Since this is our own site, when you click on the link it will load the post using your single.php template.

Next we grab the title that is returned, and then we close the link tag, moving on to grabing the pubdate - when the item was published, and then using human_time_diff we calculate how long it has been since the item has been posted. That gives us the groovy human readable 21 days ago stamp.

For the forum section, we just follow the above steps, only changing the URI of the feed to http://chrisjdavis.org/support/rss.php. Other than that everything is the same.

After the second block of RSS aggregation code, we just need to add the closing code we need and we are done:

</div><?php get_footer(); ?>

And there you have it… a letter opener

Err… sorry MST3K moment.

Seriously though, that is about it. I think you can see the potential that home.php has, freeing your site up to be just whatever you want while retaining the flexability and power that WordPress brings to the table.

So take what you have learned here and do something amazing with WordPress on your own sites, and by all means come back here and comment showing us all your brilliant work.

Until next time.

 

Podcasting with WordPress

I was asked by Matt sometime ago if I would create an entry in Codex describing how to podcast with WordPress.  There is already a nice article there, but I thought I would go ahead and create this tutorial for the sake of completeness.

Welcome those of you surfing here from 9rules, Airbag Industries, Photo Matt and Forever Geek.  I am continually surprised when someone thinks my ramblings here are worth mentioning, so thanks for the linkup Scrivs and Greg!

So here it is, I decided to record this tutorial as a podcast as well as a proof of concept.  Enjoy.

First a little background

For anyone out there who is still unaware of the phenomenon known as podcasting, lets take a moment to reflect. Podcasting is the brainchild of washed up MTV VJ who has found new life as the godfather of podcasting, and the always fashionable person to hate Dave Winer.

In a nutshell podcasting allows you to create your own audio programming and then deliver it via the web.

The socially acceptable way to distribute podcasts are through RSS enlcosures. RSS enclosures allow you to reference binary data, in our case an audio file, from within your RSS feed.

Podcast readers then subscribe to an RSS feed and download the audio files contained in the enclosures, and some like the forthcoming iTunes update will then move those downloaded audio files to your portable audio player for later consumption.

So lets look at how to podcast with WordPress shall we?

Steps to podcast with wordpress

  1. Create an audio file with the software of your choice, I am using Quicktime Pro, but there are great free alternatives like wavepad for the windows operating system, Rosegarden for Linux and Audacity for Mac OS X, Windows and Linux et al.
  2. Upload that mp3 to a server, either your own or one of the myriad, nay veritable cornacopia of servers that are available for this task. I am a big fan of the Internet Archive myself. If you use the Internet Archive you can grab the Creative Commons Uploader to make your life easier.
  3. Create a post in WordPress, in which you reference the URI of said mp3, and then hit publish.

And that’s it. Now just pimp out that RSS URI so that people can find an download your stereophonic masterpiece.

 

CJD Spam Nuker

Back in September of 2004 I released a plugin that allowed you to delete large amounts of spam with one click.

Some backstory

Basically one afternoon I was hit with a wave of spam that resulted in 1500+ comments awaiting moderation that were all spam.  That was not a fun prospect, deleting all of those comments via the admin UI.  So I took a trip to the terminal and issued one command, which wiped them all out.

So taking that experience I created a plugin that allowed you to delete comments by author, IP, email or URI.  Now fast forward to WordPress 1.5.  1.5 has some wonderful toosl to help you combat spam built in, a blacklist feature, moderation by keywords and so on.  At first I was stoked at how well these tools were working, I didn’t see any real waves of spam hitting my site, I was assuming that 1.5 was sending all that evil to /dev/null/ like a good little monkey.

I however, was very wrong.

Apparently the DEVs decided that what should happen is that anything that is considered spam will be flagged as such: ’spam’ and kept in the comments table in all our databases.  I still fail to see the usefullness of this, but that was not my call.  The point is that I was in my DB mucking around, as I am want to do, and found that I had 1500+ “spam” comments just hanging around in my comments table, with no way to interact with them from within WP.  Now for me, that really isn’t a big deal, I just fire up the old terminal, or open phpMyAdmin and delete them that way.  For the normal user though, that is another story.

Enter Spam Nuke

spam nuker!

So I being the good samaritan I am, raised a feature request bug about this, and was basically told that you should just issue the "DELETE from wp_comments WHERE comment_approved = 'spam'"; which my friends is crap.  The normal user who cares about the size of thier DB should be able to easily and quickly get rid of that chaff from within WordPress.

Well now you can.

I had been meaning to update Mass Delete for 1.5 for some time.  This answer from the DEVs gave me the impetus I needed to get it done.  This new version serves two purposes:

Getting to the features

You can still delete groups of spam as you did originally, only now Mass Delete only deletes from comments flagged as spam, when you are successful you see this message:

nuke some

The new feature is Mass Nuke, with one click you can nuke every comment in your table that is flagged as spam, when run successfully you see this message:

nuke em all!

Not really much to it, really.  Once the plugin is activated you can find it in the Manage submenu, there will be a selection labeled Spam at the end.

Here is the file you need cjd_delete.zip.  Enjoy and let me know if you find any bugs, or have any comments.

 

Christ is Born! Glorify Him!

Happy Holidays, Merry Christmas and all that rot to all my friends out there in internet land.  I am going to be away from the internet for the most part, until January 3rd, so if I don't respond its nothing personal.

I will leave you with these two gifts, firstly if you click 'All Comments' that you see under each Recent Commenter you will see a chronological listing of thier comments on this site.  For example you can see all of the comments by Michael Heilemann by going to http://www.chrisjdavis.org/history/Michael Heilemann/.

So if you are a regular commenter here and would like to see your list of comments just place whatever name you comment under after /history/ and you should be fine: http://www.chrisjdavis.org/history/your name.

The other gift is to let all oif you who have been wanting me to write a book on WordPress, looks like you have your wish.  All I can say at the moment is that I was approached to write a book, and I accepted.  I will let you know more as I am able.

 

Back Home Again

Well I have returned from another ApacheCon, and I can't wait for the next one.  This conference was much better than the last one in terms of my presentation.

I am planning on updating with a longer entry later when I have time, but for now I have work and sleep to catch up on!

 

Changes in the air

I had hinted before that the change in design here was the harbinger of more drastic, and I hope profound things to come here at Sillyness.  I guess it is time to talk a little about that now.

To really have this story hit home, you need to know a bit about who I am, and where I have come from.  While in college I studied art, not because it was the only thing that I could do, but because of all things that I could do, it was the one that promised to allow me to communicate with people long after I had passed on.

Read the rest »

 

Happy Birthday!

Today my wonderful wife, mother of my child, bestest friend turns my age!

I am not saying how old she is, but I am 28, so you do the math.  I am missing you right now Heather, and I wish I could be there with you to celebrate, know that we are going to party like its 1899 when I get home baby.

 

Apachecon US Day 2

Well we are at Day 2 and I have made my presentation.  I am not sure how I feel about it, it was better than Stuttgart but I am still not sure that it was good.

They are recording the slides and the audio of each presentation and selling them to the attendees and the speakers.  That really ticks me off that I have to pay for a recording of my own work.  But I digress; if I actually break down and buy my session I will rip the audio and podcast it... promise.

Things have been great so far, other than I haven't really had the urge to take any pictures.  I plan on taking at least a couple of pictures of the hotel, and the surrounding area... probably when I go on the Segway tour on Wednesday.

See you guys later.

Speaking

Buy my book!

Blog Design Solutions