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
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
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
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>
Thanks, I'll give that a try.
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?
Try using $this->ParsedContent() instead of $this->Content()
That gives the same result.
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
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