Author Next/Prev Article Links
2 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: February 19, 2013 (RSS)
Hi...
I was wondering how I could modify this code to show results by author only... so users can navigate to next/prev articles by the given author...
Thanks
list($prevRecord, $nextRecord, $firstRecord, $lastRecord) = getPrevAndNextRecords(array(
'tableName' => 'am_articles',
'recordNum' => $articlesRecord['num'],
'where' => 'approved = 1', // 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;
}
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
PHP Programmer - interactivetools.com