WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Customizing feeds and feed urls (9 posts)

  1. hasund
    Member
    Posted 7 years ago #

    I am using WordPress more like a CMS than a blog as such, and I want to prevent certain categories from being displayed in the main feed. I can get around this by playing with the feed url and using for example "?feed=rss2&cat=-4&cat=-5" (which excludes categories 4 and 5). However, this looks "hackish" and ugly, I want the main feed to have the default WP rss url of "http://site.org/feed".

    mod_rewrite is alive and working, but I have a hard time figuring out regular expressions and how to do this.

    Are there any .htaccess gurus out there that might know the magic code? I've tried the following, without success:


    RewriteBase /
    RewriteRule ^feed/?$ /?feed=rss2&cat=-4&cat=-5[R,L]

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    The simple way is to use the Category Visibility plugin:
    http://ryowebsite.com/?p=46

    It lets you hide categories from the feed, or the homepage, or the archives, etc, etc. Very configurable.

  3. hasund
    Member
    Posted 7 years ago #

    Ah, I had that installed already actually, but I'd forgotten about its capabilities. Thanks, it will do for now.

    However, the plugin has its limitations (hiding a category from feeds hides it from its own feed too, not just from the main feed), so I'm hoping to be able to use a mod_rewrite solution.

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    So you only want to rewrite the main feed and not all the category feeds as well?

    RewriteRule ^/feed$ /index.php?feed=rss2&cat=-4&cat=-5 [R,L]

    Should work, I think.

  5. hasund
    Member
    Posted 7 years ago #

    For some reason it doesn't. I'll try some more in the morning.

  6. Xander
    Member
    Posted 7 years ago #

    I think the least complicated thing to do is hack away at the wp-rss.php, wp-rss2.php, and other such files in the root. That's what I did, anyway. I have written code to select which categories go into the main feed without upsetting category feeds, and also insert meta data (if available) for posts in certain categories. Have at it!

  7. hasund
    Member
    Posted 7 years ago #

    I am sure there are more graceful solutions, but my resources(meaning technical knowledge and time) are limited. I got it to work in the .htaccess. Excluding more than one category doesn't seem to work, so I had to add the categories to be included instead, like this:

    RewriteRule ^feed$ ?feed=rss2&cat=1+2+3+6+7 [L]
    RewriteRule ^feed/$ ?feed=rss2&cat=1+2+3+6+7 [L]

    But of course, for every problem solved another one comes along. I noticed that my category feeds (http://site.org/feed/section/category/feed) got the title from the site, just like the main feed (http://site.org/feed) does. This makes them look indistinguishable in a feed reader, confusing users. Obviously I want the main feed to be titled "site name" and the category feeds to be titled "site name: category". It would also be nice to have category-specific links and descriptions. So I used some code found elsewhere on this forum:


    <?php
    if (is_category()) {
    foreach((get_the_category()) as $cat) {
    $titulo = get_bloginfo_rss('name') ." :". $cat->cat_name;
    $descripcion = $cat->category_description;
    $enlace = get_bloginfo_rss('url') . "/" . $cat->category_nicename . "/";
    }
    }
    else {
    $titulo = get_bloginfo_rss('name');
    $descripcion = get_bloginfo_rss("description");
    $enlace = get_bloginfo_rss('url');
    }
    ?>
    <channel>
    <title><?php echo $titulo; ?></title>
    <link><?php echo $enlace; ?></link>
    <description><?php echo $descripcion; ?></description>

    It works fine for the category feeds.

    But here's the newborn problem: Because the main feed actually is a composition of category feeds, the system interprets it as one - thus grabbing the title from the category that happens to be assigned to the first post.

    Any ideas?

  8. Xander
    Member
    Posted 7 years ago #

    Well, I usually consider mucking around with .htaccess to be anything but graceful when it comes to WP :)

    As for your current problem, a judicious use of is_home() and is_cat() should help out...

  9. hasund
    Member
    Posted 7 years ago #

    Yup, got it to work somehow...

Topic Closed

This topic has been closed to new replies.

About this Topic