_GET['cat'] Doesn’t Work With Permalinks

My sidebar shows different content based upon the category that you are viewing at the time. There are so many links that I want access to that I had to break out the big categories like bicycle and garden into their own subpages.

The other day I switched to using permalinks for the URL. This replaces the URLs like this:
WordPressSS/?post_id=763
With URLs that look like this:
WordPressSS/2008/12/22/penny-stove/

This caused a big problem with showing different sidebar content based on the category. The category used to be passed in through the query string and you get it with _GET['cat']. Permalinks don’t use query strings.

To restore functionality, you need to replace “current_cat = $_GET['cat'];” with
$category = get_the_category();
$current_cat = $category[0]->cat_ID;

It would seem the permalinks can handle multiple categories, because get_the_category() returns an array. This might be useful for some feature I can’t image. Perhaps a sidebar for a tab to show Programming+Computers+Technology content.

Leave a Reply

You must be logged in to post a comment.