WordPress.org

Ready to get started?Download WordPress

Forums

RSS feed for each category (35 posts)

  1. dewey
    Member
    Posted 9 years ago #

    I'm trying to keep the categories as nearly virtual separate blogs.

    I'm really liking word press (particularly the RSS feature) but there doesn't seem to be a way someone can get an RSS feed for all posts in an individual category.

    I've searched the codex without finding it. If this feature already exists I would apprecaite a pointer. Otherwise I would like to make it a feature request.

    Thanks,
    --
    Dewey
    dewey@sasser.com

  2. angsuman
    Member
    Posted 9 years ago #

    You can have feeds by category in Strayhorn.

    For example to get all the RSS 2.0 feeds for the Java category from my blog use:
    http://blog.taragana.com/index.php/category/Java/feed/

  3. jonasrullo
    Member
    Posted 9 years ago #

    Is there a way to have the RSS feed <title> field include the name of the category or be the name of the category?

  4. Flegme
    Member
    Posted 9 years ago #

    Sure there's a way :) i use it on my own blog. Look here :
    http://dommiers.free.fr/wordpress/index.php/category/1914-18/feed/

    all you have to do is to insert this code in the title tag of your wp-rss2.php (in the wordpress root) file. It's just under the channel node

    <title><?php bloginfo_rss('name'); ?><?php if (is_category()) echo " : " ?><?php echo single_cat_title(); ?></title>

  5. Flegme
    Member
    Posted 9 years ago #

    to be more clear, i put this code in my index page

    <?php
    $URL=get_settings('siteurl') . "/wp-content/themes/" . get_settings('stylesheet');
    $LinkToFeed=str_replace("//","/",$REQUEST_URI . "/feed/");
    $TheCat=single_cat_title('',false);
    ?>
    <div id="content">
    <?php if (is_category()) { /*If this is a category archive*/?>
    <h3><?php echo $TheCat; ?>
    <a href="<?php echo $LinkToFeed; ?>" title="RSS Feed"><img src="<?php echo $URL; ?>/img/xml.gif" alt="RSS Feed" title="RSS Feed for the category <?php echo $TheCat;?>"></a></h3>

    by this way i wrote the selected category (into the h3 tag) under my header, i personnalize my xml "icon" and i let the user choose if he want to suscribe to my rss feed for the selected category (not for all the site...) by clicking on the icon.

    I hope i've been clear, cause it's late now and my english is really not perfect :)

  6. ColdForged
    Member
    Posted 9 years ago #

    Looks perfectly understandable to me, Flegme, nice work.

  7. dixie
    Member
    Posted 9 years ago #

    Apart from that, if you need a rss for several categories you can use this code in a plugin file:

    function feed_categories_rules(&$rules)
    {
    $rules['index.php/feed/(feed|rdf|rss|rss2|atom)/([0-9,]+)/?$'] = 'index.php?&feed=$matches[1]&cat=$matches[2]';
    $rules['index.php/(feed|rdf|rss|rss2|atom)/([0-9,]+)/?$'] = 'index.php?&feed=$matches[1]&cat=$matches[2]';
    return $rules;
    }

    add_filter('rewrite_rules_array', 'feed_categories_rules');

    The function adds a two new rules to rewrite_rules so if you use a url like: http://www.example.com/index.php/feed/rss/4,5,6 you´ll get a feed with the content of 4,5 and 6 categories included their subcategories

  8. matiasjajaja
    Member
    Posted 9 years ago #

    I am a newbie, and I have to questions:

    1. In Flegmes example. Can I put that code anywhere in index.php?

    2. In Dixie example. How do I create a plug-in? (i will research this topic in the forums, but just wanted to ask)

    Thanks

  9. matiasjajaja
    Member
    Posted 9 years ago #

    Hi,

    This post:
    http://wordpress.org/support/topic/18679 did the trick for me.
    I think that one of the things that did it, was to turn on Permalinks, and the rest followed.

  10. Flegme
    Member
    Posted 9 years ago #

    Little patch for rss feed... i correct my script because there was a problem when you navigate on differents pages for a category so here is the "correctif" :

    <?php
    $URL=get_settings('siteurl') . "/wp-content/themes/" . get_settings('stylesheet');
    $LinkToFeed=str_replace("//","/",$REQUEST_URI . "/feed/");
    $TheCat=single_cat_title('',false);
    $pospage=strpos($LinkToFeed, "page");
    if ($pospage ==true) {
    $LinkToFeed=substr($LinkToFeed, 0, $pospage)."feed/";
    }
    ?>

    By the way, the user can "scroll" between pages and select the rss feed anywhere in it's navigation, not only in the front page of the selected category.

    Hope this help,

    Flegme.

  11. nieuws
    Member
    Posted 8 years ago #

    Isn't there a way in WordPress itself, it automatically does the job already for recent comments per post for example.

  12. TyskJohan
    Member
    Posted 8 years ago #

    OK, so it can be hacked. But what I want (and am trying to hack) is to make the "implicit" RSS feed announced in the header (as link-alternative, which is what browsers subscribe to) for the archive pages for a category to be the RSS feed for that category instead of the RSS feed for the whole blog.

  13. TyskJohan
    Member
    Posted 8 years ago #

    OK here is what I added to the header template, if anyone's interested.


    <?php
    if (is_category()) {
    $fullrss = get_category_rss_link(0,intval( get_query_var('cat')));
    } else {
    $full_rss = get_bloginfo_rss('rss2_url');
    };
    $rss2_url = $fullrss;
    $rss_url = $fullrss."rss/";
    $atom_url = $fullrss."atom/";
    ?>
    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php echo $rss2_url; ?>" />
    <link rel="alternate" type="text/xml" title="RSS .92" href="<?php echo $rss_url; ?>" />
    <link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="<?php echo $atom_url; ?>" />

  14. frankp
    Member
    Posted 8 years ago #

    TyskJohan, thanks, that's really handy.

    Flegme: that looks really handy, but I couldn't get it to work... could someone repost explaining where each bit of code goes...

    I tried implementing it in several places, but no joy. I'm not a php coder, so I need baby steps.... :)

    Thanks to anyone who can help...

    Also, any other tips on making feeds easier to access for users greatly appreciated.

  15. TyskJohan
    Member
    Posted 8 years ago #

    frankp, I'm afraid the code snippet I posted no longer works in WP201.

  16. frankp
    Member
    Posted 8 years ago #

    Luckily, the implementation I'm working on is an older version of WP1.5.2 :) it works nicely...

    What I'm really looking for though is a way to visually list the category feeds, on their own, for users to easily access.

    I know you can list the feeds *next* to the categories, but I want a clean list of category feed links for users to access.

    Or, as described above, even a link to the category feed from the category page. That would help...

    I wish I could code php.... :(

    Anyway, thanks for replying!

  17. myrrh
    Member
    Posted 8 years ago #

    How about something like this:
    <a href="/wordpress?feed=rss2&cat=<?php
    $cat = get_the_category(); $cat = $cat[0]; echo $cat->cat_ID;
    ?>">SUBSCRIBE</a>

  18. TyskJohan
    Member
    Posted 8 years ago #

    I think this is more portable:


    <?php if (is_category()) {?>
    <a href="<?php get_category_rss_link(1,intval( get_query_var('cat'))); ?>">Subscribe</a>
    <?php } ?>

  19. Lorelle
    Member
    Posted 8 years ago #

    This is interesting but not quite what I'm looking for. I need a list of the category specific feeds associated with that post. The categories the post is filed in.

    Suggestions?

  20. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

    Lorelle: You're saying that you want to get a link for a categories feed, for a specific post? So this would be in the loop then? I'm just trying to see what you're doing.

    Generally, you can append "feed/" to most anything you see and get a feed of it. For example, http://lorelle.wordpress.com/tag/blog-babble/feed/ is the feed of your "Blog Babble" category. But the correct way to do this is to call get_category_rss_link() with the category id. Since you might have multiple categories in a post, you can do it like this:

    <?php foreach((get_the_category()) as $cat)
    {
    echo '<a href="';
    get_category_rss_link(true,$cat->cat_ID,$cat->category_nicename);
    echo '">'.$cat->cat_name.'</a>';
    }
    ?>

    This must be in the loop. It will spit out the names of the categories, comma separated, with each name being linked to its feed.

  21. Lorelle
    Member
    Posted 8 years ago #

    This is brilliant, though the spit out didn't include commas. Just a mashed together space-less line of categories. I've been digging through tons of code and can't find how to include the commas. Fixy, please! ;-)

    Thanks so much! I've been poking at this for months without success. And you were right. I should have been more clear about the use being in the Loop on a single post (in the post meta data section). Thanks!

  22. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

    Bah. I forgot the commas. Silly me.

    In the above code, change this:
    '</a>';

    to this:
    '</a>, ';

  23. Lorelle
    Member
    Posted 8 years ago #

    It's the little things that matter. Perfect fix. THANKS!!!

  24. Lorelle
    Member
    Posted 8 years ago #

    Oh, Otto42, and anyone else paying attention. It didn't work.

    <?php foreach((get_the_category()) as $cat)
    {
    echo '<a href="';
    get_category_rss_link(true,$cat->cat_ID,$cat->category_nicename);
    echo '">'.$cat->cat_name.'</a>, ';
    }

    Returns:

    Categoryone, categorytwo, categorythree, .

    Note the additional comma and the space then period. Is there any way to make this generate the list with the commas, but recognizing NOT to put the last comma in at the end? The space and period thing I can deal with. The comma period, that ain't so nice.

    Thanks.

  25. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

    Sure. Picky, ain't ya? ;)

    <?php
    $cats = get_the_category();
    $num = count($cats);
    for($i=0; $i<$num; $i++)
    {
    $cat=$cats[$i];
    echo '<a href="';
    get_category_rss_link(true,$cat->cat_ID,$cat->category_nicename);
    echo '">'.$cat->cat_name.'</a>';
    if ($i != $num-1) echo ', ';
    }
    ?>

  26. Lorelle
    Member
    Posted 8 years ago #

    Yes, I know. I'm a raging nit-picker. And you are a total star. Give me an "and" before the last category and you are a celebrity! HA! I ask for so much, but then, I expect great things from my wonderful WordPress gurus.

    Okay, I'm slightly kidding. It would be sweet to have the "and" but this is fabulous. Thank you so much.

  27. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

    I think this slight change will add the "and" you're looking for.

    <?php
    $cats = get_the_category();
    $num = count($cats);
    for($i=0; $i<$num; $i++)
    {
    $cat=$cats[$i];
    echo '<a href="';
    get_category_rss_link(true,$cat->cat_ID,$cat->category_nicename);
    echo '">'.$cat->cat_name.'</a>';
    if ($i == $num-2) { echo ', and '; }
    else if ($i != $num-1) { echo ', '; }
    }
    ?>

  28. Lorelle
    Member
    Posted 8 years ago #

    I could reach through this screen and hug the ever-loving life out of you, Otto!!!! Brilliant. THANK YOU. KISSES!

  29. sosuke
    Member
    Posted 8 years ago #

    I have attached the above script to my footer, works almost perfect, but for some reason it is dropping categories.

    http://austinpublic.com/category/events/

    I have posts in All Events, Community and Music, but Music is not showing up, any idea why?

    Thanks for the great script though, I love it!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags