I apologize if the title of this post is a bit confusing and you have no idea what I’m talking about. I’ve spent 15 minutes trying to come up with a better explanation of this issue and this is the best that I came up with. I promise to make this more obvious with some screenshots. Onward!
1. The Issue
Many portfolio and magazine-style WordPress themes will display posts in a grid, like our own Oncanvas theme (a free portfolio theme):
The issue arises because of a core option in WordPress, specifically the “Blog pages show at most: 10” from Dashboard > Settings > Reading.
Unfortunately not all WordPress users and website administrators even know about this core option in WordPress, so they end up with a website that looks something like this:
Horrible! Just horrible!
2. The Simple Solution
At first I wanted to blame users for not knowing basic WordPress settings.
Then I wanted to blame WordPress, because it doesn’t put different value on different settings. All of them are clumped up in that Settings section, where some settings are more “valuable” but are somewhat less visible.
And then it hit me. There is a simple and elegant solution that would work for absolutely any WordPress user, no matter how well they know WordPress.
Ladies and gentlemen, I give you WordPress admin notices.
If you are (like me) not very familiar with how these admin notices work, there’s a very useful tutorial from WPMUDEV: How to Add Admin Alerts and Error Messages to the Backend of WordPress.
It didn’t take long for me to implement it into my themes, so now when you activate Oncanvas, you will get a dismissible notice like this one (minus the red border):
That’s it! Now anyone using my grid-like themes will get this simple admin notice which will disappear automatically if the setting is correct.
To make it all happen, you can use:
<?php get_option( 'posts_per_page' ); ?>
If it is not a multiple of your grid size then display an admin notice.
3. The Alternative (Not so Good) Solution
I have seen some theme developers take this matter into their own hands by adding code like this to their themes:
<?php update_option( 'posts_per_page', 9 ); ?>
To clarify, this will automatically overwrite whichever value the user already has and will set WordPress to display 9 posts per archive page.
I’m not a fan of this method. I don’t think that theme developers should force certain settings on users of their themes.
I think that a dismissible admin notice is the way to solve this common issue.
You inform the users and let them decide what they want to do. You provide them with a link to the settings page and suggest some values that will work best.
P.S. This method is also acceptable for themes hosted in the official WordPress.org theme repository, it doesn’t break any (current) guidelines.
P.P.S. The purpose of this post is to suggest a simple solution to a common problem. I don’t want to include complete code for this, as you can implement this in many ways. You can find the full code in some of my themes hosted on WordPress.org: Oncanvas, Photozoom, NewsToday.