Author Next/Prev Article Links

By gregThomas - February 19, 2013

Hi,

You should just need to add a second variable to your where statement that limits the results to the current author:

<?php


list($prevRecord, $nextRecord, $firstRecord, $lastRecord) = getPrevAndNextRecords(array( 
'tableName' => 'am_articles', 
'recordNum' => $articlesRecord['num'], 
'where' => "approved = 1 AND createdByUserNum = ".$articlesRecord['createdByUserNum'], // optional - defaults to all records in section 
'orderBy' => 'publishDate', // optional - defaults to schema listPageOrder 
));
//echo "<pre>";print_r($nextRecord); print_r($prevRecord);
if($prevRecord)
{
$arlink= $prevRecord['_link'];
$atitle= $prevRecord['title'];

foreach ($prevRecord['article_image'] as $nupload):
$narticle= $nupload['urlPath'];
endforeach;
}
if($nextRecord){
$arlink= $nextRecord['_link'];
$atitle= $nextRecord['title'];

foreach ($nextRecord['article_image'] as $nupload):
$narticle= $nupload['urlPath'];
endforeach;
}

This code is just an example, so you might need to modify it to get it working with your variables.

So I've added createdByUserNum to the where statement for the getPrevAndNextRecords function. This will limit the results to the person who created the article in the CMS.

Let me know if you have any questions. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com