Whether you think you can or you can't either way you are right.


Winners never quit and quitters never win.


Success is the ability to go from one failure to another with no loss of enthusiasm.


The best way to have a good idea is to have a LOT of ideas.


It does not take much strength to do things, but it requires great strength to decide what to do.


The journey of a thousand miles must begin with a single step.


We all die. The goal isn't to live forever, the goal is to create something that will.


I have not failed. I’ve just found 10,000 ways that won’t work.


Selling to people who actually want to hear from you is more effective than interrupting strangers who don't.


I’ve failed over and over and over again in my life, and that is why I succeed.


We are told that talent creates its own opportunities. But it sometimes seems that intense desire creates not only its own opportunities, but its own talents.



12 best quotations on success in plain text

“Whether you think you can or you can’t either way you are right” -Henry Ford

“Winners never quit and quitters never win” -Vince Lombardi

“Success is the ability to go from one failure to another with no loss of enthusiasm” -Sir Winston Churchill

“The best way to have a good idea is to have a LOT of ideas” -Linus Pauling

“It does not take much strength to do things, but it requires great strength to decide what to do” -Elbert Hubbard

“The journey of a thousand miles must begin with a single step” -Lao Tzu

“We all die. The goal isn’t to live forever, the goal is to create something that will” -Chuck Palahniuk

“I have not failed. I’ve just found 10,000 ways that won’t work” -Thomas Edison

“Selling to people who actually want to hear from you is more effective than interrupting strangers who don’t” -Seth Godin

“I’ve failed over and over and over again in my life, and that is why I succeed” –Michael Jordan

“We are told that talent creates its own opportunities. But it sometimes seems that intense desire creates not only its own opportunities, but its own talents” –Eric Hoffer

“You must do the thing you think you cannot do” –Eleanor Roosevelt

(images from Wikipedia)

Related Posts:

So you want to be a blogger… But what should be the topic of your blog? Is it OK to blog about your dog? Well, why not. Since people are finding success tweeting shit their dads say then why wouldn’t you be successful blogging about your dog…

Anyway, maybe doing a little research is a better idea after all, hence this post. To find out what I’m on about feel free to check out my guest post at YoungPrePro.

12 Audacious and Creative Niche Searching Ideas for Your Blog

Once you have your niche there are still some things yet to do. For example, you have to decide which domain is right for you, you have to find a WordPress theme (remember, free WordPress themes are evil), and last but certainly not least – you have to find some blog traffic sources.

Related Posts:

While looking at my backlinks today, I noticed a site in French had linked to my post about making photo galleries. He mentioned that the Google Translate wasn’t great. I took a look, and while I don’t know how good the text translation was, I did notice that Google strangely tried to translate the code as well, thus screwing it all up.

A quick search revealed that all one had to do was to add the “notranslate” class to any wrapping object to prevent its contents from being translated.

Now, I use the Syntax Highligher Evolved plugin to display code on my site (although I use an older version because I like the look and functionality of it better than the latest version). So I edited the plugin and found where it inserts the PRE tag, and added the notranslate class to it. And voila, now my code doesn’t get translated anymore.

Just a helpful tip for anybody who posts code on their sites.

Google rolled out their +1 button today. So I added it here. You’ll find it below all the posts. Try it out.

Here’s the simple-stupid plugin I wrote to do it. While you can just edit your theme, I like making these sort of things into plugins. That way, I can turn them off at will, and I know exactly where to go to change them without having to dive into my theme code. Also, if I change themes, the code still works on the new theme.

Plugin Name: Otto's Google +1 Button
Description: Add a +1 button after the content.
Author: Otto
Version: 999

add_filter('the_content', 'google_plusone');

function google_plusone($content) {
	$content = $content.'<div class="plusone"><g:plusone size="tall" href="'.get_permalink().'"></g:plusone></div>';
	return $content;

add_action ('wp_enqueue_scripts','google_plusone_script');

function google_plusone_script() {
	wp_enqueue_script('google-plusone', 'https://apis.google.com/js/plusone.js', array(), null);

I wrapped the button in a div so that I could style it. In my particular case, I’m floating it right and giving it a margin, same as the Twitter and Facebook plugins. One day, I’ll make all these little Google plugins more generic and configurable, and roll them into a Simple Google Connect plugin. :)

One thing I don’t like is that the +1 button only works for people who are logged into a GMail account. Sorry Google Apps users, you’re out of luck. Complain to Google until they fix it.

If you want to add more parameters to the plugin and reconfigure it, you can find out about the available parameters here: http://code.google.com/apis/+1button/#configuration

Just upgraded to the beta of 3.2. I like the new admin interface overall. Really, I do. But relatively minor things tend to bug me sometimes.

For example, I don’t much care for the Site Title being so tiny and hidden at the top of the admin screens. I like the site’s name to be big and prominent, as it’s a link to the front end of the site. On multi-site, it’s awfully nice to see at a glance what site I’m on. I often click that link to go to the front end of the site easily. So trying to navigate to the front end became difficult and hit or miss with this title being so tiny.

I also don’t like seeing the Page Title being so big and having a big ol’ icon there beside it. The Page Title strikes me as kinda useless. I mean, I know what screen I’m on.

So I wrote a quick tweak plugin to fix it. I’m posting it in case it bugs you as much as it bugs me. On a side note, it’s a quick little demo of how to modify the WordPress admin CSS quickly and easily.

Plugin Name: Embiggen Site Title for WordPress 3.2 beta
Description: Embiggen the Site Title in wp-admin. Debiggen the Page headers. Ditch the useless icon.
add_action('admin_print_styles', 'big_site_title');
function big_site_title() {
.wp-admin #wphead {
	height: 42px;
.wp-admin #wphead h1 {
	font-size: 28px;
	#font-family: "HelveticaNeue-Light","Helvetica Neue Light","Helvetica Neue",Helvetica,Arial,sans-serif; #uncomment this if you want to go to the sans-serif font
.wp-admin #header-logo {
	background-image: url("images/logo.gif");
	background-size:32px 32px;
.wp-admin .wrap h2 {
	padding-top: 1px;
	padding-bottom: 0px;
.wp-admin .icon32 {

Feel free to tweak further as desired. Also, WordPress might change further before 3.2 is released, so this may stop working or need further tweaking.

The annual WordPress conference, WordCamp San Francisco (home of the very first WordCamp), is now accepting speaker applications. Past speakers have included core WordPress developers, people building successful businesses on WordPress, popular bloggers, people from related projects and businesses…you name it. In addition to Matt Mullenweg’s annual “State of the Word” address, WCSF has played host to talks by people like Mark Jaquith, Matt Cutts, Richard Stallman, Scott Berkun, Karl Fogel, Tim Ferriss, Tara Hunt, Chris Pirillo, and John Lilly. With 3 days of content this year instead of just one, the list of speakers should be even more impressive. If you think you’d make a good addition to this year’s roster, check out the WCSF Call for Speakers.

google alertsIf you haven’t been using Google Alerts before then let me tell you that you’ve been missing out… This is one of those Google tools that’s not that heavily advertised so some people don’t even know it exists. So please let me, just in one sentence, tell you what this tool can do for you.

Google Alerts can send you a notification WHENEVER someone mentions your name (or your business name) somewhere on the internet.

There’s no better way of getting various information on what people are talking about your products (or your services, or your company, or you personally, or even about what your competition is up to) delivered straight to your inbox or RSS reader. What it means is that you can monitor the online presence of your brand at all times.

This is a very powerful knowledge, I’m sure you understand this. If you know what people are saying you can always react to it with a proper message. You can put out fires around your accidentally flawed products, give discounts for every testimonial (as a surprise, of course, not as an incentive to receive one), or make it work for you in any other form.

(There’s a lot more interesting Google projects, so if you want to be up to date with what’s going on feel free to check these out: 10 Google Labs Experiments You Should Know, 31 Useful Google Blogs To Keep Yourself Up To Date.)

Now let’s get to the point and learn how to set up Google Alerts.

How to set up Google Alerts and make it work for you fulltime

Setting up Google Alerts is pretty simple. Start by logging in to your Google account. Go to: http://www.google.com/alerts and activate the service. What you’ll see is something like this:

how to set up google alerts

It’s a simple form, just a handful of fields. The first one (“Search terms”) is the most important. Simply input the term you want to monitor. You can use all the standard google search operators there. So for example, if I want to monitor the occurrences of my twitter username around the internet the simplest thing to do is to just input “carlosinho”. But since twitter actually does a better job at monitoring itself then I want to exclude the results coming from twitter.com, that’s why instead of a simple one-word phrase “carlosinho” I would use “carlosinho -site:twitter.com”. This will exclude all the results from twitter.com, and give me only what’s left. This is just an example.

You can use whatever term you like. It can be something as simple as your own name. Or your business name. Or names of your main competitors if you want to be up to date with what they’re doing.

I’m using Google Alerts primarily for monitoring my blog’s name, its URL, my own name, and the most important keywords for my blog.

I will get a little more in-depth into how this actually works in a minute, but for now let’s just focus on the other fields.

The second field is “Type”. The default setting for it is “Everything” and I advise you to leave it that way. It means that Google will keep an eye on every type of content (videos, blog posts, tweets, articles, etc.). Eventually, if you end up with too many notifications besieging your inbox you can switch to a little more targeted monitoring, but “Everything” is a good starting point.

The next field is “How often”. At the time of writing this post you can choose from three settings: “As-it-happens”, “Once a day”, “Once a week”. It’s Google asking how often you want to receive notifications. “Once a week” sounds reasonable because you don’t want to have your inbox flooded with alerts… this is what you’re probably thinking right now, but in reality “as-it-happens” is the best setting here. I will tell you why in a minute.

The next field is “Volume”. Two options here: “Only the best results”, “All results”. There’s not much for me to explain here. I don’t know the algorithm responsible for deciding what the best result is and what isn’t, so you’ll just have to test it yourself. You can start with “All results” and then switch to “Only the best results” if you find notifications not that strongly related to your search term.

Last field is “Deliver to”. This field provides you with two possible options: your gmail address, and “Feed”. The best choice here in my opinion is “Feed”. If you select this and press the “Create Alert” button you will be given a custom RSS feed. You can use this feed in your favorite RSS reader, or if you’re using Google Reader the feed will automatically appear there. This feed will contain notifications about the occurrences of your search term around the internet.

How alerts work

What happens behind the scenes in Google Alerts is actually simple. Google Alerts provide a kind of window looking inside the Google Search Engine. What Google Alerts basically does is it looks at the current Google index and monitors it for any new entries. When a new entry appears and it gets indexed for your desired search term Google Alerts lets you know about it.

It means that there’s only one flaw in this whole system. And that is you won’t be notified the minute something appears on the internet, but the minute Google stumbles upon it. Depending on the site where the mention actually happened the time difference between the mention appearing and Google finding it may be anywhere between 2 seconds and 2 months (a rough estimate). Despite this flaw the whole system is still working very well and providing valuable results.

Now let’s take a look at some clever examples of using Google Alerts.

How to create a RSS feed for a site that doesn’t have one

Yes, Google Alerts can help you with this one too. All you have to do is input the site address preceded by “site:” as your search term. For this blog it would be “site:newinternetorder.com”. Then choose “Feed” as the delivery method and hit the “Create Alert” button.

What you will end up with is an alert notifying you about every new page within a given domain. Quite similar to what a standard blog RSS feed actually is. There is a slight delay with this method though, as I was saying earlier.

You can use Google Alerts for some interesting things. Like, for example, monitoring how often Microsoft is mentioned on the Apple website (simply by using “Microsoft site:apple.com” as your search term), or monitoring every new squidoo lens on guitar playing (“guitar playing site:squidoo.com”), or monitoring what people are saying about a piece of software called Market Samurai on Warrior Forum (“market samurai site:warriorforum.com”), or what they are saying about Warrior Forum itself in various places online (“warriorforum -site:warriorforum.com”).

Or maybe you’re interested in some WordPress advice. You can try “wordpress ~advice”. The “~” operator gives you all terms that are similar to “advice” (like: tips, questions, tutorial). The possibilities are endless.

Here’s a challenge for you. You already know how to set up Google Alerts so now try to come up with an interesting search term for new alerts and then share it in the comments. I’m looking forward to seeing your ideas.

P.S. There’s more tutorials like this one on this blog. For example: how to install nofollow blogroll links on your WordPress blog, and how to create a YouTube background.

Related Posts:

visual presentationsIf you’re into exceptional visual presentations, presentation designs and visualizations in general then this is going to be a treat for you. However, if you’re not… well, sorry.

A lot has been said on how to create a great presentation. The basic rules are somewhat simple, but sticking to them and providing the information you want at the same time is a completely different story. That’s why many people struggle with it (myself included).

First, some how-to information. For those of you who want to learn interesting tactics and methods of creating great presentations here are some valuable resources:

How to Prepare Public Presentations that Knock the Socks Off by writetodone. This article gives a complete tutorial on how to create a memorable presentation. And it surely deserves a spot on a must-read list of every presentation designer.

Start your presentation with PUNCH by Presentation Zen. The beginning of a presentation is probably the most important part. If you want to have any kind of impact you have to grab your audience by the throat. Boredom is the worst enemy of every presenter.

Not to toot my own horn here, but I have my two cents in the discussion as well. Feel free to check out two posts of mine: 2 Slides That are Ruining Your Damn PowerPoint Presentation and How to Screw up Your Presentation in Just One Single Step.

OK, back to the topic. As promised, here’s a list of some exceptional visual presentations for your inspiration.

29 Presentations That are Slapping-Your-Mamma-Good

Let’s start with a set of presentations by an organization called the RSA. Their YouTube channel (RSA) is full of great talks that have one thing in common. They are all visualized by hand drawings appearing on the screen in real time. Here’s what I mean:

The Secret Powers of Time

Drive: The surprising truth about what motivates us

Changing Education Paradigms

21st century enlightenment

Smile or Die

Where Good Ideas Come From

The guys at Common Craft present a similar style when it comes to visualizing their presentations. However, they are using cool paper cuttings instead of real time drawing. Apart from that, their “Plain English” series provides a lot of value explaining many things that may at first seem difficult to explain.

Twitter in Plain English

Blogs in Plain English

Social Networking in Plain English

World Wide Web in Plain English

RSS in Plain English

Borrowing Money in Plain English

Electing a US President in Plain English

and finally…

Zombies in Plain English

The next package comes from GOOD Magazine. Completely different style than RSA’s or Common Craft’s (as many of the videos are not even narrated), but still, exceptional visualizations that are truly entertaining to watch.

Catch Me If You Can

Business Uncertainty

Drinking Water

The State of the Planet


Nuclear Weapons

Of course, these three channels don’t have a monopoly for great visualizations, and there’s a lot more stuff out there. For example, these:

History of the Internet

The Animated Guide to Polish Success

Imagining the Tenth Dimension

MC Yogi – Vote For Hope

Origami In the Pursuit of Perfection

This list would not be complete without a couple of classy TED talks:

Seth Godin on the tribes we lead

Seth Godin on standing out

Hans Rosling shows the best stats you’ve ever seen

Now it’s your turn to share. Shoot me a comment and link to some great visual presentations. I will make sure to update this list with your entries.

P.S. Happy Mother’s Day! ;) (for those of you who don’t know, in Poland the 26th of May is the Mother’s Day).

Related Posts:

This site carries financial news, including market data, from the US, and around the world.

Urban Legend web was contracted to update server-side PHP code, and the timing of automatic feeds, to ensure data stability.

We also made some small presentational changes to the table data.

I have seen many questions from people about how to create photo galleries in WordPress. But often I see these questions answered by somebody recommending a plugin or something like that. You don’t really need plugins to create photo galleries. WordPress has a huge amount of gallery functionality built right in. You just need to make your theme smarter in order to take advantage of it.

Note: Matt has one of the neatest photo gallery implementations around, and he often gets questions about it. So I’m going to refer to it from time to time in this post. Maybe you’ll want to head over there and familiarize yourself with some of the look and features of it.

Understanding the Gallery Concept

One of the first things you need to know is how WordPress organizes Galleries. A gallery is really just a post with a bunch of images attached to it.

While editing a post or creating a new one, you have the option to upload images or other files. When you upload a file through the file Uploader, WordPress creates a post just for that file. This post has a post_type of “attachment”. Images in particular get some extra processing, and they show up in multiple sizes, you can insert them into the posts, etc. You probably already knew that. You probably have seen the gallery inserter, which just inserts the “gallery” shortcode into your post.

What you might not have known is that it’s doing more than you think. It’s not just resizing those images you’re uploading, but it’s pulling out metadata and other information about the image too. It’s grabbing alot of the EXIF data from the image and storing it as postmeta items for that attachment post. The post itself, being a post, gets its own URL, which is the post that it is attached to’s URL followed by the attachment posts title. Basically, an attachment post is sorta like a child of the parent post, which contains the gallery. So all a gallery really is is the sum of the attachments posts that are children of the gallery post itself.

Graph of the Gallery concept

Is that clear as mud? Don’t worry, it’s simpler to work with than you think.

Create an Image Template

First thing you need to do is to edit your theme (or create a child theme, if you prefer). What you’re going to do is to make an “image.php” file.

(Side note: If you browse through the source of WordPress, you’ll never find where it loads the “image.php” file, because it isn’t there. What it is actually doing is looking for the mimetype of the attachment as a filename. So since you uploaded, say, a JPG file, then the mimetype is image/jpeg. It splits that and looks for image.php, followed by jpeg.php, followed by image_jpeg.php, and finally just attachment.php as the generic base. It does this for any and all attachments, and any and all mime types. So you can have a video.php for video attachments, audio.php for audio attachments, etc.)

The image.php file is the template that will load for “single images”. A gallery shows thumbnails, but when you click on them, you go to the attachment page for just that image. An easy way to start with your custom image page is to copy your existing single post page to it. Just copy single.php to image.php. If you don’t have a single.php, maybe you should try copying the index.php file instead.

Modify your Image Template

Since this is an image, it’s going to have things in it that normal posts don’t. It’s also going to need special navigational entries that other posts don’t have.

For starters, it has a parent, which is the post containing the gallery. So what if we want to display the gallery post’s name? Easy, we can reference the parent using $post->post_parent. So code like get_the_title($post->post_parent) will get us that title so we can echo it. Similarly, using something like get_permalink($post->post_parent) will get us the link back to the gallery. So this sort of code in our image template will display that link:

echo "<a href='" . get_permalink($post->post_parent). "'>Go back to ". get_the_title($post->post_parent) ."</a>";

For navigation, we have special functions. previous_image_link and next_image_link will let us display links to the previous or next images in the gallery order. Each of these takes two parameters. The first is the size of the previous or next image we want to display (or false to not show a thumbnail at all), the second optional parameter is some text to put in the link. So to show a couple of text navigational links, this code would work:

echo previous_image_link(false,'Previous Photo');
echo next_image_link(false,'Next Photo');

If I wanted to display image links instead, I could change that false to ‘thumbnail’ to display the thumbnail sized images. Or ‘medium’. Or whatever size I preferred.

Next we want to display the image. The wp_get_attachment_image function takes care of that easily:

echo wp_get_attachment_image( $post->ID, 'medium' );

The second parameter there is the size we want to display it at. You could also use ‘large’, ‘full’, ‘thumbnail’, etc. Any of the image sizes. If you want the image to be clickable, you might wrap it in an A tag and link it to the image itself.

But remember that attachment posts are still posts. All those fields you can enter on the image uploader are available to you to use. For example, the “Title” is stored in the normal Post Title field, so calling the_title() will display that. The Description is stored in the Content field and can be displayed with the_content(). The Caption is stored in the Excerpt field and can be displayed with the_excerpt(). You should use these as needed.

EXIF Information

Here’s an example of one of Matt’s single image pages, showing a balloon: http://ma.tt/2011/05/balloon-ride/mcm_9033/.

Nice shot. Scroll down a bit and look on the right hand side of that page, where it says INFO. Lots of nifty information there. But he didn’t put any of that in, WordPress did it all by itself.

To gain access to that information in your image.php file, you use this code:

$imagemeta = wp_get_attachment_metadata();

If you examine this array, you find that it contains widths, heights, filenames of the various sizes of thumbnails generated, etc. But it also contains an array called “image_meta”. This is an array of information that represents everything WordPress was able to glean from the image itself. After you know this, it’s just a matter of displaying it properly.

For example, to display the camera name, he has code similar to this:

if ($imagemeta['image_meta']['camera']) {
	echo "Camera: " . $imagemeta['image_meta']['camera'];

There’s other bits in there, like Aperture, Focal Length, ISO settings, and Shutter Speed. Most of these are straightforward, except for shutter speed which is often not in an easy format to display. Usually it’s a fractional value, represented as a decimal. Often we want to convert this to the fractional display. Here’s a bit of code I wrote to do that. It’s not perfect, but what is?

if ($imagemeta['image_meta']['shutter_speed']) {
	echo 'Shutter: ';

	// shutter speed handler
	if ((1 / $imagemeta['image_meta']['shutter_speed']) > 1) {
	echo "1/";
		if (number_format((1 / $imagemeta['image_meta']['shutter_speed']), 1) ==  number_format((1 / $imagemeta['image_meta']['shutter_speed']), 0)) {
			echo number_format((1 / $imagemeta['image_meta']['shutter_speed']), 0, '.', '') . ' sec';
		} else {
			echo number_format((1 / $imagemeta['image_meta']['shutter_speed']), 1, '.', '') . ' sec';
	} else {
		echo $imagemeta['image_meta']['shutter_speed'].' sec';

Ugly, I know, but it gets the job done, more or less. Works on most shutter speeds I’ve tested it with.

Gallery Formatting in the Stream

Now, obviously you want your posts to look good in the normal flow of the blog as well. Twenty-Ten and the upcoming Twenty-Eleven themes both show you how to do this rather easily. Twenty-Ten used the “gallery” category for this at one point, before Post Formats came along and made that method obsolete. Now it uses the gallery post format instead.

So first, obviously, your theme will need to support the gallery post format. This is easy, just add this to your theme’s functions.php if it doesn’t have gallery support already (or add “gallery” to it if it does have post format support).

add_theme_support( 'post-formats', array( 'gallery') );

Now that that’s done, you have the option of choosing gallery as a post format. So you need to edit your theme to use that flag as an indicator to display things differently.

There’s plenty of tutorials on post formats out there, so I’ll assume you’re more than capable of figuring out how to use has_post_format(‘gallery’) or the “.home .format-gallery” CSS indicators to style the posts as needed.

What you need to know for specific gallery formatting in the main stream of the blog is how to display a selected representative image from the gallery there instead of the whole thing. There’s two basic steps to this.

First, you have to write your post appropriately to begin with. Take one of Matt’s posts for example: http://ma.tt/2011/05/20/

Here’s how that post actually looks in the editor:

Description text at the top here... Went for balloon ride, etc.
< !--more-- >
[ gallery ]

In other words, he puts the description first, then the more tag, then the gallery after it. This has the effect of giving a natural separation of the description content and the gallery itself. The gallery is not displayed on the front page, because it’s after the more tag. So a call to the_content() on the stream pages will only show the description.

Secondly, you can easily adapt the Featured Image function to let you choose which image to display in the stream. All the user has to do is to upload their gallery then select one and set it to be the featured image. Voila, it’ll be the main representative one used.

if ( has_post_thumbnail() ) {
        // use the thumbnail ("featured image")
        $thumb_id = get_post_thumbnail_id();
	the_post_thumbnail( $size ); // whatever size you want

By tossing a div around that, you can then float it left, or right, or whatever you prefer to do. With some extra code and the use of the get_children function, you can make this default to the first image in the gallery if they don’t choose a featured image.

else {
	$attachments = get_children( array(
		'post_parent' => get_the_ID(),
		'post_status' => 'inherit',
		'post_type' => 'attachment',
		'post_mime_type' => 'image',
		'order' => 'ASC',
		'orderby' => 'menu_order ID',
		'numberposts' => 1)
	foreach ( $attachments as $thumb_id => $attachment )
		echo wp_get_attachment_image($thumb_id, $size); // whatever size you want

Using tricks like this, you can get the bits of the gallery yourself and display them in different ways.

Make a Gallery Specific Page Template

Matt’s Gallery Page is itself customized. It displays the galleries in an entirely different way. There’s a big copy of the featured image, along with a few thumbnails below the description, and it even has a count of the images in each “album”. This is all done with a pretty straightforward page template.

So to start, make a Page Template:

Template Name: Gallery

Right at the top of the template, we’re going to add a special taxonomy query, which will get all the gallery posts (as well those in the gallery category, since we’re being backward compatible and all). So here’s the code:

$args = wp_parse_args($query_string);

         'tax_query' => array(
                'relation' => 'OR',
                        'taxonomy' => 'post_format',
                        'terms' => array('post-format-gallery'),
                        'field' => 'slug',
                        'taxonomy' => 'category',
                        'terms' => array('gallery'),
                        'field' => 'slug',
        'paged' => $args['paged'],
) );

First we parse the normal arguments, then we override them with our own query. The only argument we really use from the normal set is the page number, for multiple paging.

Our overriden query uses an advanced taxonomy query. In this case, it selects any posts in the gallery post format, or any post with a category of gallery. By passing this to query_posts, we override our main page query, and thus our main Loop will now display the gallery posts only.

After this, it’s just a matter of displaying what we want to display.

The main Loop itself is pretty straightforward. To display that featured image, we use essentially the same code as we used before, only passing it a bigger size.

To display the description, we just use the_content() as per usual. One thing we have to do though is to set the global $more value to zero, so that it stops at the !–more– tag, preventing it from continuing to display the whole gallery.

Getting the count turns out to kinda suck. There’s no good function in WordPress to do this for you easily. So, reluctantly, I resorted to an SQL query.

echo $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = '$post->ID' AND post_type = 'attachment'" ) .' PHOTOS IN THIS SET';

The four thumbnails you can do using the get_children trick. However, there’s a catch. We don’t want to display the featured image as one of those four thumbnails. So, since we’ve already displayed that image (see the code above), we have the $thumb_id variable still. So we’ll use that to not get that image. Like so:

$attachments = get_children( array(
	'post_parent' => get_the_ID(),
	'post_status' => 'inherit',
	'post_type' => 'attachment',
	'post_mime_type' => 'image',
	'order' => 'ASC',
	'orderby' => 'menu_order ID',
	'numberposts' => 4,
	'exclude' => $thumb_id )
foreach ( $attachments as $img => $attachment ) {
	echo '<a href="'.get_permalink($img).'">'.wp_get_attachment_image( $img, $size ).'</a>';

By using the exclude parameter, we can get the first four images in the gallery without getting that featured image again, if it’s in those first four images.


Andrew Nacin pointed out that I can combine the act of getting those four children and getting the attachment count into a single new WP_Query, like so:

$images = new WP_Query( array(
    'post_parent' => get_the_ID(),
    'post_status' => 'inherit',
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'order' => 'ASC',
    'orderby' => 'menu_order ID',
    'posts_per_page' => 4,
    'post__not_in' => array($thumb_id),
    'update_post_term_cache' => false,
) );

This creates a new secondary query that I can loop through like so, to show the children:

foreach ($images->posts as $image) {
	echo '<a href="'.get_permalink($image->ID).'">'.wp_get_attachment_image( $image->ID, $size ).'</a>';

It also has the side benefit of doing the primary counting of the images for me, via the SQL_CALC_FOUND_ROWS that WordPress uses in full-blown queries. However, the count will be off by 1, since we’re excluding the featured thumbnail. Therefore, I just have to add one to it:

echo ($images->found_posts+1) . ' PHOTOS IN THIS SET';

That combines both of those elements into one query instead of two, and eliminates the need for the direct SQL query.

(Side note: I also set ‘update_post_term_cache’ to false to prevent it from doing an extra query to get the terms for these posts into the internal memory cache. This saves us a bunch of unnecessary queries, since I’m not using the terms here anyway. Using full WP_Query objects instead of the simpler ones like get_children can take a little bit more thought and effort, but can save you time in the long run, if used wisely.)


Throughout this post I’ve used $size as a generic indicator of where to put the size parameter. WordPress creates sized images by default, as we all know. These are thumbnail, medium, large, and full which is just the full sized uploaded image, unmodified.

But WordPress can create other sizes too, if you like. At different points throughout Matt’s gallery pages, you’ll see images displayed in all sizes. These sizes are custom, and they’re added in the functions.php file.

add_image_size( 'nav-thumbnail', 100, 100, true );
add_image_size( 'random-thumbnail', 200, 150, true );
add_image_size( 'gallery-thumbnail', 250, 200, false );
add_image_size( 'gallery-large', 660, 500, false );
add_image_size( 'gallery-pagethumb', 70, 70, true );

The add_image_size function takes a width, a height, and a flag to cause it to crop or not. So those tiny thumbnails on the gallery are “gallery-pagethumb” sized, and are 70×70, cropped. Anywhere I need one of those sizes, I can just pass that parameter instead of $size and voila.

Obviously though, adding too many sizes is undesirable, because it takes time to create those sizes (they’re created on upload of the images), and it takes storage space to store them. Hopefully a future version of WordPress can work around this issue.


These are the basics of making cool galleries, without plugins, without special uploaders, and while being able to style it to match your theme. Play with it. Experiment. There’s a ton of functions in WordPress specifically for dealing with these. Take a look through wp-includes/media.php and look at some of the function names. You might be surprised.