Show Page name on a recent review/comment

Permalink
Hi I have a site that lists several business and users are able to comment on each one. There is also a seperate page where all the reviews pull through to. The code pasted below is what does this, it works perfectly BUT now the client wants the Page name to appear as well and I cant figure out the correct code for that.

In order for the below to work I had to modify the reviews addon to allow extra fields to be added as well as insert the values in the database.
<?php     
defined('C5_EXECUTE') or die("Access Denied."); 
$db = Loader::db();
$nav = Loader::helper('navigation');
$query = "SELECT * FROM btReviewsEntries ORDER BY entryID DESC LIMIT 5";
$recent_reviews = $db->getAll($query);
foreach($recent_reviews as $rev) {
   echo '<div id="mainreview">';
   echo '<div id="titlereview">'.$rev['commentTitle'].'</div>'; // comment title
   echo '<div id="commentreview">'.$rev['commentText'].'</div>'; // comment text, probably want to trim it 
   echo '<div id="readm"><a href="'.$nav->getLinkToCollection(Page::getByID($rev['cID'])).'">View Listing</a></div>'; 
   echo '</div>';
         }
?>


I found this line of code from the recent comments add on and tried to play around with it but no success.

echo '<cite>'.$entry['user_name'].' on <a href="'.BASE_URL.view::url('/').'index.php?cID='.$entry['cID'].'">'.$page->getCollectionName().'</a></cite>';


Thanks Maria

agentorange
 
ScottSandbakken replied on at Permalink Reply
ScottSandbakken
To get the current page name:
Page::getCurrentPage()->getCollectionName();


To get the referenced page:
Page::getByID($rev['cID'])->getCollectionName();
agentorange replied on at Permalink Reply
agentorange
Hi Thanks for the quick reply!

I did the following now and it worked

I added this

$page = Page::getByID($rev['cID']);


right after

foreach($recent_reviews as $rev) {


and added this to display the name

echo '<div id="pagename">Review on '.$page->getCollectionName().'</div>';


Here is the complete code

<?php     
defined('C5_EXECUTE') or die("Access Denied."); 
$db = Loader::db();
$nav = Loader::helper('navigation');
$query = "SELECT * FROM btReviewsEntries ORDER BY entryID DESC LIMIT 5";
$recent_reviews = $db->getAll($query);
foreach($recent_reviews as $rev) {
   $page = Page::getByID($rev['cID']);
   echo '<div id="mainreview">';
   echo '<div id="pagename">Review on '.$page->getCollectionName().'</div>'; 
   echo '<div id="titlereview">'.$rev['commentTitle'].'</div>'; 
   echo '<div id="commentreview">'.$rev['commentText'].'</div>';  
   echo '<div id="readm"><a href="'.$nav->getLinkToCollection(Page::getByID($rev['cID'])).'">View Listing</a></div>'; 
   echo '</div>';
         }