Mar 16 2009

Using WP_Query in WordPress 2.7

So I was trying for the last week or so to use three loops on a single page, to display categorized pages, and couldn’t figure out why it didn’t work. (I used the plugin page category plus to put pages in categories).

Anyways, if you want pages to be shown in a categorical listing, use post_type=page in the query string. Otherwise it’ll only show posts by default, which didn’t happen in previous versions! Mine looked like this: <?php $sportsQuery = new WP_Query(‘category_name=Sports Pages&post_type=page’); ?>

//Loop goes here…

Hope this helps somebody. I know I’ll be coming back to it when I forget!

For more info see: http://codex.wordpress.org/Template_Tags/query_posts


Mar 16 2009

How to do multiple virtual hosts on OS X

  1. Download and install VirtualHostX (don’t forget to back up your existing config!!)
  2. Download and install Gas Mask (manages multiple hosts files, dumb name though)
  3. If you want to do this with WordPress and you have a database locally and another one on a dev server somewhere, you can do the following code:

if(eregi(“^mywebsitename.com$”, $_SERVER[HTTP_HOST]))

{

define(‘DB_NAME’, ‘dbremotename’);

/** MySQL database username */

define(‘DB_USER’, ‘dbremoteuser’);

/** MySQL database password */

define(‘DB_PASSWORD’, ‘dbremotepassword’);

/** MySQL hostname */

define(‘DB_HOST’, ‘dbremotehost’);

define(‘WP_SITEURL’, ‘http://mywebsitename.com’);

define(‘WP_HOME’, ‘http://mywebsitename.com’);

}

else{

define(‘DB_NAME’, ‘dbremotename’);

/** MySQL database username */

define(‘DB_USER’, ‘dblocaluser’);

/** MySQL database password */

define(‘DB_PASSWORD’, ‘dblocalpassword’);

/** MySQL hostname */

define(‘DB_HOST’, ‘dblocalhost’);

define(‘WP_SITEURL’, ‘http://mywebsitename.com’);

define(‘WP_HOME’, ‘http://mywebsitename.com’);

}


Mar 16 2009

HTML Special Characters

Any good web designer knows certain characters have to be encoded in HTML.

Here’s a list of pretty much every character and it’s encoding: http://webdesign.about.com/library/bl_htmlcodes.htm

Bonus: Need to use some encoded characters in your PHP script? Use html_entity_decode() to turn them into regular text.


Mar 16 2009

OS X Server Tips

To enable PHP:

  • nano /etc/apache2/httpd.conf
  • uncomment LoadModule php5_module…

To enable mod_rewrite

  • In the primary site configuration, change AllowOverride to AllowOverride All AuthConfig
  • Restart apache with sudo apachectl restart