• 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 https://myblogsitez.org/?cat=2&feed=rss2 rather than this:

    <title>The Main Title for the Blog</title>
    <link>https://myblogsitez.org</link&gt;
    <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>https://myblogsitez.org/?cat=2</link&gt;
    <description>This is the category description, rather than main blog descript.</description>

    Does that make sense? Is it possible?

    Thanks!
    – J.

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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…

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

    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: https://validator.w3.org/feed/

    Hope it helps.

    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>
    [...]

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

    $enlace = get_bloginfo_rss(‘url’) . “/” . $cat->category_nicename . “/?feed=rss2”;

    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!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘can RSS feed title reflect the category info?’ is closed to new replies.