Jump to content

Recommended Posts

Posted

Thanks Diogo

I tried this:

<?php
      $lotes = $pages->get(1025)->children();
      function getFirstPara($string) {
      $string = substr($string,0, strpos($string, "</p>")+4);
      return $string;
      }
      foreach ($lotes as $lote) {
      echo getFirstPara($lote->body);
      }
?>

And it worked great !!! :D

  • Like 1
Posted

Great!

You might want to move that function to a file that is called by all the others, so you have it available averywhere, like _func.php or even the head file if you prefer.

  • Like 1
Posted

In the latest 3.x version, there's also some nice additions that will let you easily do this.

http://processwire.com/blog/posts/processwire-3.0.7-expands-field-rendering-page-path-history-and-more/#render-groups

Nice. Funny that there is a regex example that seems to do what ts wants.

<?php

// render the first found paragraph only

if(preg_match('!(<p>.+?</p>)!', $value, $matches)) {

echo $matches[1];

}

Regex is basically voodoo to me so i don't quite understand the exclamation marks but i'm sure Ryan has a better grasp :)

Posted

The exclamation marks are simply pattern delimiters. Normally, this is "/", but PHP looks for the first character in a pattern string and treats it as the delimiter. This comes in handy whenever you have a pattern containing a forward slash, as you'd otherwise have to escape it to tell PHP that it's part of the pattern and not its end.

  • Like 1
  • 2 years later...
Posted

As a follow up question to the first paragraphy solutions provided. Is there a way to get "the rest of the text" output? A way to exclude the first paragraph?

The result I am looking for is to output the first paragraph from a body text field, then an image from an image field, and then the rest of the text from the body text field. So there might be other solutions?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...