17488 Posts in 4473 Topics by 1978 members
| Go to End | Next > | |
| Author | Topic: | 3179 Views |
-
Blog - show full post

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
-
Re: Blog - show full post

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> -
Re: Blog - show full post

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?
-
Re: Blog - show full post

31 August 2008 at 9:26am
Try using $this->ParsedContent() instead of $this->Content()
-
Re: Blog - show full post

31 August 2008 at 11:16am Last edited: 31 August 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
-
Re: Blog - show full post

3 September 2008 at 8:41am Last edited: 3 September 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
| 3179 Views | ||
| Go to Top | Next > |



