views:

201

answers:

1

In WordPress plugin coding, if I have two categories (cars and gardening) and I want to always exclude gardening from all queries, what is the intercept (hook or other trick) I need to do to do this? I need to always exclude gardening whether it be via search, tag cloud widget, comment widget, calendar widget, and any other portion of the website.

The reason I ask is that my client needs to have a single theme react differently by domain name coming in. If the user types gardening.com and it's mapped to this blog, then he wants to restrict to show only gardening.com content. If the user types cars.com and it's mapped to this same blog, then he wants to restrict to show only cars.com content.

Said again, my question lies in the area of wanting to hit one central place of WordPress with a plugin hook to always ensure the queries are restricted to a given category. That way, even if a new plugin is added that's not a default coming with WordPress, it will also be restricted by category too.

I have already figured out how to slip this code in the header.php of a theme to make the links act properly depending on whichever URL someone types in:

$sURL = 'http://' . $_SERVER['SERVER_NAME'];
update_option('siteurl',$sURL);
update_option('home',$sURL);
unset($sURL);
A: 

I found I had to create a home.php that was a copy of index.php, but tack on a query_posts('category_name=' . $_SERVER['SERVER_NAME']) call before the have_posts() call. On index.php, I left it alone and didn't add the query_posts(). Then, I had to make an archive.php that was a copy of Kubrick's archive.php, and then edit that so that I change query_posts() differently depending on what was chosen to do, such as add "&tag=", "&year=", etc. As well, a search.php had to be added (borrowing from Kubrick) that did a restriction too by category. This was a big help:

http://codex.wordpress.org/Template_Tags/query_posts

The only thing I haven't figured out yet is how to restrict widgets in the dynamic sidebar to a category. I'm making that into a separate request in StackOverflow.

Volomike