We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11858
    • 130 Posts
    I’ve been browsing the phx modifiers at http://wiki.modxcms.com/index.php/PHx/CustomModifiers and I was wondering if there was a way to show just the first paragraph? like phx:word_limit and phx:character_limit but something like phx:paragraph_limit?

    Thanks!
      • 11858
      • 130 Posts
      Has anyone discovered a solution to this yet by any chance?
        • 26931
        • 2,314 Posts
        Hi Hat-rack,

        not sure if it’s 100% the right way to do it, but i just tested it, and it seems to work

        create a new snippet and call it "phx:firstp" with the content of:
        <?php
        $firs_par = explode( '</p>', $output );
        $firs_par_output = strip_tags( $firs_par[0] );
        return '<p>'.( $firs_par_output ).'</p>';
        ?>

        then in your Ditto Template-Chunk use it like this: [+content:firstp+]

        going to test it further
          • 23672
          • 1 Posts
          Maybe
          <?php
          return strstr($output,'</p>',TRUE).'</p>';
          ?>
          

          is faster. but im not sure. and its not tested. if you have content before the first "<p>" you can do something like that:

          <?php
          return strstr(strstr($output,'<p>'),'</p>',TRUE).'</p>';
          ?>
          

            • 26931
            • 2,314 Posts
            ah, thanks...i think strstr before_needle is only available from PHP 5.3 on (nicer solution though)