WordPress.org

Ready to get started?Download WordPress

Forums

can RSS feed title reflect the category info? (7 posts)

  1. jmoonah
    Member
    Posted 8 years ago #

    Hi folks.

    I recently installed 2.0 and it's working great. What I'd like to do is have RSS feeds for particular categories contain the TITLE, DESCRIPTION and ideally LINK of the category rather than the main blog. In other words, if I'm looking at the RSS feed for a category like http://myblogsitez.org/?cat=2&feed=rss2 rather than this:

    <title>The Main Title for the Blog</title>
    <link>http://myblogsitez.org</link>
    <description>This is the over-all description for the blog.</description>

    I'd like this to appear in the RSS:

    <title>My Category Title</title>
    <link>http://myblogsitez.org/?cat=2</link>
    <description>This is the category description, rather than main blog descript.</description>

    Does that make sense? Is it possible?

    Thanks!
    - J.

  2. Diplo
    Member
    Posted 8 years ago #

    Hi J.,

    I'm trying to find a solution. So far, I've arrived to this one:

    Modify /wp-rss2.php:

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

    But still the description doesn't appear...

  3. Diplo
    Member
    Posted 8 years ago #

    ...because I forgot to add descriptions to my test categories... the script works;-)

  4. Diplo
    Member
    Posted 8 years ago #

    And I discovered (luckily) get_bloginfo_rss() which allows the code to be nicer (or at least less messy;). Add these lines before your <channel> definition:


    <?php
    if (is_category()) {
         foreach((get_the_category()) as $cat) {
             $titulo = $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>
    [...]

    You can check the result afterwards at: http://validator.w3.org/feed/

    Hope it helps.

  5. Diplo
    Member
    Posted 8 years ago #

    My excuses, I forgot to add a closing tag. This is the script:


    <?php
    if (is_category()) {
      foreach((get_the_category()) as $cat) {
        $titulo = $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>
    [...]

  6. Diplo
    Member
    Posted 8 years ago #

    Hope this time is right... the feed link is missing:

    $enlace = get_bloginfo_rss('url') . "/" . $cat->category_nicename . "/?feed=rss2";

  7. audat
    Member
    Posted 7 years ago #

    hi,

    i just added the code on my blog and it works fine (except one issue:)

    one of my categorys has a subcategory. the feed of this parent-category is unfortunately named after its sub category (also the hyperlink within the feed: it links to the subcategory)...

    $titulo = $cat->cat_name; this field in my database has the correct value
    (the name of the cat)

    thanks if anybody can help me!

Topic Closed

This topic has been closed to new replies.

About this Topic