Scott Nellé.com

Archive for the 'wordpress' Category

Load A Page Into A WordPress Theme Outside Of The Loop

Wednesday, September 23rd, 2009

I build a fair number of WordPress sites on small budgets for my employer, Union Street Media. Sometimes I need to give our clients an editable region in the sidebar, away from the main blog/page content. Here’s a quick and dirty trick I use to pull a page into a theme outside of the loop:

 <?php
// must use a variable for page id
// http://codex.wordpress.org/Function_Reference/get_page
$id = 3;
$p = get_page($id);
echo apply_filters('the_content', $p->post_content);
?>

You can get your page ID by editing the page. It will show up in the url (the ‘post=x’ portion.) It’s important to note that you have to pass a variable to the get_page() function. If you just pass an integer it will throw a fatal error. No need to go into why that is; just keep it in mind. get_page() essentially wraps get_post() so that function’s documentation is a good place to start if you want to learn what’s available to you.

This isn’t a particularly pretty solution, but it’s quick and it works well provided you know your page IDs and you’re not making a theme for distribution. I like to name my page something like ‘**Sidebar Content’ so it is easy to differentiate from regular pages.

WordPress 301 Redirect Plugin Released

Wednesday, September 2nd, 2009

I’m very pleased to announce that I’ve released my first WordPress plugin. It’s called Simple 301 Redirects and it does just what it says on the tin. It provides an interface for redirecting URL requests. It’s handy for when you’ve migrated a site to WordPress and are unable to maintain the URL structure. With Simple 301 Redirects you can redirect your old urls like “/about.html” to new, clean URLs like “http://www.yoursite.com/pages/about/” or whatever you like. Redirecting your old links to new destinations is important for preserving inbound links and pagerank after migrating a site. And this plugin does it in the easiest possible way I could think of.

You can read a little bit more about the plugin at its official home on this site or go straight to the WordPress plugin directory to download it. I hope you find it helpful!

Simple 301 Redirects Plugin Screenshot