21475 Posts in 5781 Topics by 2620 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 991 Views |
-
Show "x" number of comments?

9 November 2010 at 3:22pm Last edited: 9 November 2010 3:22pm
Hi All,
I'm really enjoying the flexibility and work flow of SilverStripe, awesome! I know I will have to code this somehow, but I was wondering if someone has implemented a way to show "x" number of comments with forward and back buttons, and maybe if they could share how they did it? Actually, I would like to be able to do something like this for a lot of things, such as news articles perhaps, so things don't scroll for miles on the page. I would appreciate any pointers.
Thanks!
-
Re: Show "x" number of comments?

9 November 2010 at 6:42pm Last edited: 9 November 2010 6:43pm
I believe comments is setup to show 10 comments before beginning pagination, so you could edit the core file PageComment.php, the static variable $comments_per_page.
For creating pagination for other dataobjects you can do the following.
ReviewArticle.php
<?php
/*
* Custom Class for Review home page
*
*/class ReviewHolder extends Page{
public static $db = array();
public static $has_one = array();
public static $has_many = array(
'Reviews' => 'Review'
);public static $default_child = "Review";
/**
* Returns dataobject set containing reviews
* @RETURN DataObjectSet
**/
function getAllReviews() {
if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1){$SQL_start = 0;
$get = "Review";
$where = NULL;
$sort = NULL;
$join = NULL;
$limit = "{$SQL_start}, 2";
$reviews = DataObject::get($get, $where, $sort, $join, $limit);
return $reviews;}else{
$SQL_start = (int)$_GET['start'];;
$get = "Review";
$where = NULL;
$sort = NULL;
$join = NULL;
$limit = "{$SQL_start}, 2";
$reviews = DataObject::get($get, $where, $sort, $join, $limit);
return $reviews;
}
}}
class ReviewHolder_Controller extends Page_Controller{
}
?>
in the $limit field change the the number 2 to your desired number of objects to show.and on your template you can do this
ReviewHolder.php<% if getAllReviews %>
<% control getAllReviews %>
<div class="review">
<a href="reviews/$URLSegment">$GameCover.setWidth(160)</a>
<h1><a href="reviews/$URLSegment">$Title.XML</a></h1>
$Content.LimitCharacters(250)...<a href="reviews/$URLSegment">Read More</a>
</div>
<% end_control %>
<% if getAllReviews.MoreThanOnePage %>
<p id="pagination">
<% if getAllReviews.PrevLink %>
<a class="previous" href="$getAllReviews.PrevLink">Prev</a> |
<% end_if %>
<% control getAllReviews.Pages %>
<% if CurrentBool %>
$PageNum
<% else %>
<a class="pageNum" href="$Link" title="Go to page $PageNum">$PageNum</a>
<% end_if %>
<% end_control %>
<% if getAllReviews.NextLink %>
|<a class="next" href="$getAllReviews.NextLink">Next</a>
<% end_if %>
</p>
<% end_if %>
<% end_if %>
Hope that helps -
Re: Show "x" number of comments?

9 November 2010 at 7:25pm Last edited: 9 November 2010 7:41pm
Oh wow thanks IOTI! That is great. This is a awesome community thanks for the help and quick reply!
:0)
p.s. you know I didn't even realize that automatic pagination was built in, that is so cool. Thanks for pointing that out to me, I didn't have that many comments on my test page. I would really like to try the pagination with other data objects so that bit of code will come in really handy.
| 991 Views | ||
|
Page:
1
|
Go to Top |


