Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Blog - show full post


Go to End


9 Posts   4839 Views

Avatar
planetbrain

Community Member, 12 Posts

29 August 2008 at 9:46am

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

Avatar
BLU42 Media

Community Member, 71 Posts

30 August 2008 at 2:21am

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>

Avatar
planetbrain

Community Member, 12 Posts

30 August 2008 at 8:44am

Thanks, I'll give that a try.

Avatar
planetbrain

Community Member, 12 Posts

31 August 2008 at 8:36am

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?

Avatar
(deleted)

Community Member, 473 Posts

31 August 2008 at 9:26am

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

Avatar
planetbrain

Community Member, 12 Posts

31 August 2008 at 9:41am

That gives the same result.

Avatar
ajshort

Community Member, 244 Posts

31 August 2008 at 11:16am

Edited: 31/08/2008 11:16am

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

Avatar
planetbrain

Community Member, 12 Posts

3 September 2008 at 8:41am

Edited: 03/09/2008 8:43am

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

Go to Top