Yesterday, I covered five WordPress Code snippets to love and I hope you love these, today, just as much.
These aren’t the best 10 WordPress code snippets that I’ve gathered these past two days, but those that one should usually use on a fairly regular basis (aside from the more obvious ones?).
These lists weren’t certainly meant to be comprehensive or anything, so if you have any you would like to throw into the hat, be sure to leave them in the comments.
We would love to see them!
1. Custom Menu
Ever since WordPress 3.0, menus are much easier to add and edit by the user.
You’ll use it at least once, maybe more, if you have some extra places you drop-in extra menus.
[cc lang=”php”] ‘Navigation’, ‘sort_column’ => ‘menu_order’ ) ); ?>[/cc]
If you are building a theme to offer as a download, then you will likely use the theme_location parameter so that users can specify their own menu/multiple menus.
Custom Menu’s. Love’em.
2. Dynamic Sidebar
This depends how fancy you’re building your theme, but if you’re going to add a sidebar, it might as well be dynamic!
Of course, don’t forget to drop this in your functions.php file.
[cc lang=”php”] ‘
‘before_title’ => ‘
‘after_title’ => ‘
And now you’re stylin’!
3. Get Header/Footer/Sidebar
If you want your pages to display different sidebars, headers or footers than your blog posts or specific pages, this is what you’re going to use.
Of course, be sure you have your sidebar-extra.php setup, first.
4. Auto-Updating Date
Great theme development is all about the details. With this snippet, your copyright year will auto-update.
[cc lang=”php”]© ORGANIZATIONNAME. All rights reserved.[/cc]
5. List Recent and Random Posts
This is great for front pages, while the random posts can be good to list at the end of your posts, too.
It’s all up to your imagination!
List Recent Code
Take a look at the various parameters on the WordPress Codex.
List Random Code
5, ‘orderby’ => ‘rand’ );
- WordPress Codex.
Drop any of your favorite WordPress snippets off in the comments!
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) : ?>