We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21417
    • 486 Posts
    Hello,

    I am wanting to use Ditto to display the first 3 paragraphs of news items on a site I am building but am not sure how to limit it to paragraphs only.

    I see in the documentation it talks about truncating - the code below shows truncating to 400 characters - but this cuts words off mid sentence.

    Is there a way to limit the [+summary+] to the first 3 paragraphs? Either that, or to stop the words from being cut off during the summary and and add ’...’ at the end of the last word?

    My Ditto Call is as follows:
    [[Ditto? &startID=`49` &parents=`49` &truncLen=`400` &tpl=`intranet-news` &tplFirst=`intranet-news-first` &paginate=`1` &extenders=`summary,dateFilter` &paginateAlwaysShowLinks=`1` &orderBy=`createdon DESC` &tagData=`summary`]] 
    


    My template is as follows:
    <div class="news">
     <h2><a href="[~[+id+]~]" title="[+longtitle+]">[+title+]</a></h2>
     <p>[*newsDate*]</p>
     [+summary+]
     <a href="[~[+id+]~]" title="Read the whole story" class="more">More...</a></p>
    </p> 
    </div>


    Also I have created a TV called newsDate which is the date of the news release (not the date created):
    a. is it possible to sort the news items by the newsDate TV? and;
    b. how do I display it in the ditto summary - at the moment no date is included because I guess it is a TV from another page?

    Thanks so much in advance - I really, really appreciate it.
      Web design Adelaide
      http://gocreate.com.au
      • 20413
      • 2,877 Posts
      See http://modxcms.com/forums/index.php/topic,34709.msg210786.html#msg210786  smiley


      a and b ---> &orderBy=`newsDate DESC` then in ditto template [+newsDate+]
        @hawproductions | http://mrhaw.com/

        Infograph: MODX Advanced Install in 7 steps:
        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
        • 21417
        • 486 Posts
        Thanks mrhaw - the TV inserting / sorting is fixed - thanks for that.

        I think you might have misunderstood my initial query.

        Rather than limiting the number of words to a specific number - or the number of characters to a specific number - I want to limit the number of paragraphs to 3 per news item.

        (in this situation: different news items would have different length paragraphs, and a different amount of paragraphs)

        In other words, I want the [+summary+] to display the entire content in the first 3 paragraphs for each news item (eg after 3 </p> tags in the [content] area.

        So if the content for one news item is:
        <p>blah blah blah 1</p>
        <p>blah blah blah 2</p>
        <p>blah blah blah 3</p>
        <p>blah blah blah 4</p>
        <p>blah blah blah 5</p>

        I want the summary to display:
        <p>blah blah blah 1</p>
        <p>blah blah blah 2</p>
        <p>blah blah blah 3</p>

        Rather than limiting characters:
        <p>blah blah blah 1</p>
        <p>blah blah bl</p>

        or limiting words:
        <p>blah blah blah 1</p>
        <p>blah blah...</p>

        Any ideas on how to do it for the first 3 paragraphs for each news item?
          Web design Adelaide
          http://gocreate.com.au
          • 27708 MODX Staff
          • 2,502 Posts
          You can use the summary &truncAt and manually ad the splitter to your document. So after the 3rd paragraph you could add <!--splitter-->.

          Another option would be to create a plugin to add <!--splitter--> after the 3rd instance of the </p> by using regex. I may be overcomplicating but like everything in MODx there are many ways to accomplish.
            Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
            • 21417
            • 486 Posts
            Thank you kindly for your suggestion smashingred.

            Manual, whilst an option, will be tricky and cumbersome for the client to maintain and remember each time they create a new news item. Also given MODx is such a genius, dynamic would be better.

            I like the sound of what you are saying re regex (create a plugin to add <!--splitter--> after the 3rd instance of the </p> by using regex) but unfortunately I have absolutely no idea how to implement what you are talking about (I am a css’er).

            Further to mrhaw’s link on http://modxcms.com/forums/index.php/topic,34709.msg210786.html#msg210786%C2%A0:

            If limiting the number characters is this:

            <?php
            $output_truncated = substr($output, 0, $options);
            $output_truncated.= "...";
            return $output_truncated;
            ?>
            
            with...
            [*YOURTVNAME:len:gt=`25`:then=`[*YOURTVNAME:character_limit=`25`*]`:else=`[*YOURTVNAME*]`*]
            


            And limiting the number of words is this:
            <?php
                 $retval = $output;
                 $array = explode(" ", $output);
                 if (count($array)<=$options)
                 {
                 $retval = $output;
                 }
                 else
                 {
                 array_splice($array,$options);
                 $retval = implode(" ", $array).'...';
                 }
                 return $retval;
            ?>
            
            with...
            [*YOURTVNAME:word_limit=`3`*]


            Any ideas on the phx (or equivalent) for limiting the number of paragraphs?

            Or the way to create a plugin to add <!--splitter--> after the 3rd instance of the </p> by using regex?

            Thanks again in advance.

            All the best.
              Web design Adelaide
              http://gocreate.com.au
              • 29703
              • 217 Posts
              Did you ever work this out? I’m still struggling with trying to limit paragraphs.

              There must be a simple way of using PHx to remove the third <p> and everything that follows?
                • 21417
                • 486 Posts
                Hi thehen,

                I never worked out a dynamic method (I’m a css’er not a programmer and don’t have a handle on phx or regex).

                But I did work out a way with double handling - by manually copying the relevant paragraphs from the "Document content" box and pasting into a template variable.

                It takes a bit more time when creating a news item, but at least it works!

                I ended up double posting this query in another section because I thought it may have been more relevant there. I have documented the template variable method there:
                http://modxcms.com/forums/index.php/topic,35723.msg216396.html#msg216396

                I hope that helps you in the meantime.

                If you ever find out a dynamic method to do it, I would love to know about it.

                All the best.
                  Web design Adelaide
                  http://gocreate.com.au
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  I usually have clients just paste what they want in the summary into the Summary (introtext) field, which is actually what it is originally intended for; in fact Ditto originally by default used that field as its summary text. I nagged the dev team into putting the (summary) bit into the field label because I could never remember what it was called in the database and got sick of having to open the database and look at the field names of the site_content table to remember what to put in the [*introtext*] tags!
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 21417
                    • 486 Posts
                    thanks for clarifying that sottwell - using introtext is a great idea - I use that for meta keywords though as I don’t like how MODx does keywords (I find it much easier and less finicky just typing the keywords into the introtext field of a document than going to different screens to setup up the keywords and then click / assign per page). I think MODx should have a keywords field for each document rather than the current system.
                      Web design Adelaide
                      http://gocreate.com.au
                      • 29703
                      • 217 Posts
                      Quote from: nickf08 at Jun 19, 2009, 05:23 AM

                      thanks for clarifying that sottwell - using introtext is a great idea - I use that for meta keywords though as I don’t like how MODx does keywords (I find it much easier and less finicky just typing the keywords into the introtext field of a document than going to different screens to setup up the keywords and then click / assign per page). I think MODx should have a keywords field for each document rather than the current system.

                      I personally use tagged blogging using Ditto and call the tags in the keywords meta. In the description meta I use the introtext - works like a treat. If you have any problems with html tags appearing in the head, you can always use phx:notags.

                      I’m looking into writing something that removes anything after the last three paragraphs. I will let you know how it goes smiley