How to have a static category/author page?

The answer is essentially the same as my Edit 2 code. I must have had a typo the first time? I’ve tried to comment on what each thing does… The code works but the comments could be way off. I’m new at this. Also, this same code should work your author archive.

As one helpful person pointed out, this code is really useless and is not at all what WordPress intended. However, with a static page you can use your theme templates to make a nice “category archive” and add the loop at the bottom of the page selecting to only show the correct category. Almost like having a whole new homepage for each topic you like to blog about!

// This works!
// right when you request the site this function is called
add_action( 'request', 'yoursite_request' );

function yoursite_request($query_vars) {

    // Do things to select %some-category% name here
    // www.domain.com/category/%some-category%

    // Do things to select the %category-archive%
    // %category-archive% = www.domain.com/category/%some-category%
    // Every time someone loads %category-archive% the static page will be called instead

    if ( %category-archive% ) {
        $category_name = %some-category%;

        // This changes the wp_query to a specific page (replacing the archive query)
        $query_vars = array( 'pagename' => $category_name );
    }
    // returns the new query array back to wordpress...
    // leaving you with a static page for a category archive
    return $query_vars;
}

Also, if you use this code with the code in my last question/answer – how to use a different domain/subdomain for authors/catagories on single site? then you can get category/author sub/domains each with their own static page (and I think there is plenty of info, and even a plugin or two, for adding the loop to any page.. though I haven’t looked yet)

Leave a Comment