Forums

RSS Category Feed shows normal post list (2 posts)

  1. joezim007
    Member
    Posted 9 months ago #

    On WP 3.2.1, we've run into several cases where we need a feed of a category, but when you try to go to the feed, it just shows the normal category page.
    Ex:
    http://thebullyexpert.com/category/blog/
    http://thebullyexpert.com/category/blog/feed

    Does anyone know why this is? We have an in-house theme developer. Is he missing something? I wouldn't think so, because as far as I know, the feed capability is built into WP.

    I tried another test, by switching to a different theme. With the new theme, the feed works. Is there something that a theme might be adding or not adding that might prevent this from working correctly?

  2. joezim007
    Member
    Posted 9 months ago #

    Found the problem. Our developer got some code from the forums. When a template is assigned to a category, this code makes that template apply to all subcategories as well. Thanks to anyone who might have been trying to help.
    Here's the code if you're wondering:

    function load_cat_parent_template() {
        global $wp_query;
    
        if (!$wp_query->is_category)
            return true; // saves a bit of nesting
    
        // get current category object
        $cat = $wp_query->get_queried_object();
    
        // trace back the parent hierarchy and locate a template
        while ($cat && !is_wp_error($cat)) {
            $template = STYLESHEETPATH . "/category-{$cat->slug}.php";
    
            if (file_exists($template)) {
                load_template($template);
                exit;
            }
    
            $cat = $cat->parent ? get_category($cat->parent) : false;
        }
    }
    add_action('template_redirect', 'load_cat_parent_template');

Reply

You must log in to post.

About this Topic

Tags