Announcement

Collapse
No announcement yet.

truncating the description text on RSS feed using external.php

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • truncating the description text on RSS feed using external.php

    I do not want my RSS feed to include the entire text of the posting. I want it to only output the first 50 words as a description field to force people back to the site if they want to read the entire posting. Currently, there are three fields in the xml file that contain the entire posting. $article_description, $article[atom_content], $article[content][encoded] all include the entire post in them by default.

    Therefore, I need some changes to the external.php file. Here is what I need to do for each the RSS, RSS1, RSS2, and XML feeds:
    1. Remove the two content fields - $article[atom_content] & $article[content][encoded]
    2. Truncate the text in the description field to 50 words $article_description
    I tried the following regular expression match and inserted it just before this line: "# Each specs shared code is entered in full (duplicated) to make it easier to read"

    Code:
        // added to test truncating the text 
        preg_match("/([\S]+\s*){0,50}/", $description, $description);
        $description = trim(description[0]);
        // end addition for truncating text
    However, this is not working to truncate the description as I intended.

    Can someone help me comment out each of the full content fields and truncate the test in the description field? I have made several attempts at searching the internet for this over the last few weeks and have not been able to find the answer.

    Thank you.

  • #2
    Maybe try:

    Find:
    PHP Code:
    $description trim(description[0]); 
    Add After:
    PHP Code:
    $description substr($description050); 
    <Onimua> Congrats Chroder
    <Onimua> You're a daddy.
    <Chroder> eh
    <Onimua> :)
    <Chroder> uh oh

    Comment


    • #3
      That I believe would cut it down the first 50 characters while I want the first 50 words. The code in the preg_match line should cut it down to the first 50 words. I inserted the substr line just to test it out and it is still not trimming the text in the description field.

      Comment


      • #4
        Oh, sorry, thought the code you posted was from vB, didn't realize you added that. Delete the code I told you to add and I think your problem is that you are missing a $ in your variable.

        PHP Code:
        $description trim(description[0]); 
        Should be:

        PHP Code:
        $description trim($description[0]); 
        Also, I think you might have to change the value of the array key to 1 or 2, I forget which.
        <Onimua> Congrats Chroder
        <Onimua> You're a daddy.
        <Chroder> eh
        <Onimua> :)
        <Chroder> uh oh

        Comment


        • #5
          I spent two hours last night reading other VB forums until I found a link to this code: Truncate RSS Feed Modification for external.php I had been searching on slightly different words so I never found it. (And the person who linked to it used "click here" for the link text which did not help it show up in any google searches.) Surprisingly only 14 people have clicked install, but it seems to work fine for me with 3.6.5

          Thanks for trying to help.

          Comment


          • #6
            Russophile: Regarding this: Truncate RSS Feed Modification for external.php

            I don't know how you made this work with 3.6.5 as you said you did because I tried it and I still have the whole post...

            Hack activated with "Yes" and Number of words set at "100".

            Comment


            • #7
              I did not do anything particularly special. I will post all my settings just in case it is one of the other settings that makes the difference. See attachments. Hope that helps!
              Attached Files

              Comment

              widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
              Working...
              X