RSS
 

Posts Tagged ‘php’

WordPress 3.0, multi-sites, and migrating only some of your posts

13 Jul

I started my original blog a little over a year ago now simply as a way to have a place to post thoughts online. As it progressed and I started to flesh out my music site, I realized that I actually have at least 3 distinct types of thoughts I want to post: music-related, general commentary on my life, hobbies, and interests, and philosophical topics.

WordPress is extremely powerful, and I quickly began using its RSS functionality to feed my music related posts to my music website, but, as it turns out, this is kind of bad from a search engine perspective. I ended up using cross-domain canonical URLs to make Google happy. Additionally, it was kind of confusing. While I don’t really have much traffic to any of my sites, I like to pretend that I do, and it just wasn’t adding up.

Then comes WordPress 3.0 which allows you to host multiple blogs (even, unofficially, on multiple domains), so it gave me the opportunity to allocate content correctly to my domains.

There are drawbacks, of course.  It’s not like you get to just make posts and decide which domain you want it on.  You still have separate sites with separate management profiles, etc., it’s just that anytime you upgrade core components (such as themes, plugins, and even WordPress itself) you don’t have to do it for every blog.

Plus, all your content is in a centralized, easily accessible place.  Perhaps in the future more fine-tuned enhancements will evolve, but for the time being all I had to do was some MySQL footwork (in moving the right posts to the right blogs, which was simple enough as I already had “Music” and “Philosphy” categories).

I have had crimulus.com reserved for some time as my “personal” site — projects I’m working on, hobby showcases, etc., but I never really fleshed it out.  My music site, jeremytharp.com, is about 5 years old now, but it relayed podcast data, music news, etc. for anyone visiting that site, but, for a search engine, it treated it as if it were hosted on my actual blog which is at coffeecuphalfmoons.com.

To summarize, I just wanted to express how pleased I am with the feature as well as inform any readers (if you exist) of the changes.

Finally, for the technological grit, if anyone else intends to do this, I had to make a modification to my coffeecuphalfmoons.com theme.

I had plenty of indexed content, so now most of those are on crimulus.com or blog.jeremytharp.com, so links from search engines would generate a 404.  I simply modified my theme’s index.php send a GET request for the $_SERVER['REQUEST_URI'] on each of the domains (crimulus.com and blog.jeremytharp.com) in the event that have_posts() returned false.  If either of those requests returns a header code other than 404, I send a 301 redirect for that.

So, a search engine refers a user to http://www.coffeecuphalfmoons.com/a/post/that/i/moved/

I check (using cURL) to see if http://www.crimulus.com/a/post/that/i/moved/ or http://blog.jeremytharp.com/a/post/that/i/moved/ returns a 200, 301, etc.  If so, then it’s probably the post that was originally referred to.

This is how you help keep pagerank value and link-juice when you’re migrating only a few posts from a blog on one domain to a blog on another.  At least, that’s how I did it.

 

WORDPRESS HOW-TO: Ignore/Hide A Category On Your Home Page

28 Feb

Sometimes you don’t want a particular category to appear on your WordPress home page.  For me, I create weekly Twitter digests, and I’d rather they not be part of the page welcome.

The process of hiding them actually took me a little bit to figure out, so I thought I’d share.  It’s rather simple, so don’t blink!  :)

Simply edit “index.php” in the wp-content/themes/<your_theme_here>/ directory.

Between the lines:

<?php if (have_posts()) : ?>

and

<?php while (have_posts()) : the post(); ?>

Insert the line:

<?php if (is_home()) { query_posts("cat=-XXX"); } ?>

Be sure to replace “XXX” with the unique numeric ID of the category you want to ignore.  To find the ID, log into your admin, navigate to your categories, and select the one you want to ignore.  The number will then appear in the URL.

NOTE: Make sure you don’t delete the “-” before the “XXX” or else you will ONLY show entries from the category.

If you update your theme, you will probably have to repeat this procedure.

If you want to hide multiple categories simply append the other categories to the string with a comma: (Example: “cat=-12,-82,-4″)

It also follows, then, that this technique can also be used to hide tags, posts, etc.