Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Blog - show full post

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1 2
Go to End
Author Topic: 3521 Views
  • planetbrain
    Avatar
    Community Member
    12 Posts

    Blog - show full post Link to this post

    Does anyone know if there is a way to have the blog summary page only display the "show full post" link only if there is more to display than what is already being displayed.

    many thanks

  • BLU42 Media
    Avatar
    Community Member
    71 Posts

    Re: Blog - show full post Link to this post

    Hi-

    You certainly can! I tried this...

    In your BlogEntry.php file:

    class BlogEntry extends Page {
       .
       .
       .
       function ShowFullPost() {
          if ($this->Content == $this->ParagraphSummary()) {
             return false;
          } else {
             return true;
          }
       }
    }

    In your /templates/Includes/BlogSummary.ss file:

       <p class="blogVitals">
          <a href="$Link#PageComments_holder" class="comments" title="View Comments for this post">$Comments.Count comments</a>
          <% if ShowFullPost %> | <a href="$Link" class="readmore" title="Read Full Post">Read the full post</a><% end_if %>
       </p>

  • planetbrain
    Avatar
    Community Member
    12 Posts

    Re: Blog - show full post Link to this post

    Thanks, I'll give that a try.

  • planetbrain
    Avatar
    Community Member
    12 Posts

    Re: Blog - show full post Link to this post

    This doesn't quite seem to work for me!

    It always returns true , and displays the link

    The ShowFullPost function is definitely being called, as if I reverse the true/false return values then it always returns false.

    Any ideas what might be wrong?

  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: Blog - show full post Link to this post

    Try using $this->ParsedContent() instead of $this->Content()

  • planetbrain
    Avatar
    Community Member
    12 Posts

    Re: Blog - show full post Link to this post

    That gives the same result.

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Blog - show full post Link to this post

    I think the problem is in the fact that the FirstParagraph() function in the Text class does all sorts of fancy substrings and stuff like that - so it will return a slightly different result. I think something like this would be a better solution, as it uses the same logic checking as the FirstParagraph() function when checking for new paragraphs:

    Note I havent tested it with the blog module, but the algorithim itself should work.

    class BlogEntry
    {
       
       public function ShowFullPost()
       {
          if(self::$allow_wysiwyg_editing) {
             if(strpos($this->Content, '</p>') === false) return false;
             if(strpos($this->Content, '</p>') == (strlen($this->Content) - 4)) return false;
             else return true;
          } else {
             if(strpos($this->Content, "\n\n") === false) return false;
             if(strpos($this->Content, "\n\n") == (strlen($this->Content) - 2)) return false;
             else return true;
          }
       }
       
    }

    Edit: fixed up formatting

  • planetbrain
    Avatar
    Community Member
    12 Posts

    Re: Blog - show full post Link to this post

    Well I struggled to get any of the previous suggestions to work and ended up with the following rough and ready solution.

    class BlogEntry extends Page {
    .
    .
    .
    function ShowFullPost() {
    if ( strlen($this->Content) > ( strlen($this->ParagraphSummary()) -7 ) ) {
    return true;
    } else {
    return false;
    }
    }

    .
    .

    }

    This assumes (probably incorrectly) that the ParagraphSummary is simply the first paragraph wrapped in a <p>....</p> tag, hence the -7

    3521 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.