Creating an Automatic News Archive - 2018 Version
3 posts by 2 authors in: Forums > CMS Builder
Last Post: May 2, 2018 (RSS)
By jreddigital - April 22, 2018 - edited: April 22, 2018
Hi,
I would like to do exactly what mizrahi, requested in this Post 2234008 [https://www.interactivetools.com/forum/forum-posts.php?postNum=2234008#post2234008]
My url for the test News Archive page is : http://strafford.org/newsarchiveList.php
Current news items are shown on the home page of http://strafford.org and on this page http://strafford.org/notices.php
Using the same table "notices_srpc" which holds news items, I would like to have items older than a year appear on another page "newsarchiveList.php"
When I add Greg's suggested code from Post 2234008 for s separate listing of items a year old, as below, the page does not appear at all.
// load records from 'notices_srpc'
list($notices_srpcRecords, $notices_srpcMetaData) = getRecords(array(
'tableName' => 'notices_srpc',
'loadUploads' => true,
'allowSearch' => false,
'where' => "`createdDate` < '".date('Y-m-d H:i:s', strtotime('-1 year'))."')"
'ignoreRemoveDate' => true,
));
If the 'ignoreRemoveDate' is removed from the above, I get an error message as follows:
MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND `notices_srpc`.hidden = 0 AND `notices_srpc`.publishDate <= NOW() AND (`no' at line 3
I noticed a forum post from a user in Post 2235844 https://www.interactivetools.com/forum/forum-posts.php?postNum=2235844#post2235844 that they received this kind of message after a server move.
Indeed after the CMSB was updated by you guys (thanks again) this site was recently moved to a new and better host. I suspect, however, that the where query isn't structured correctly.
I have left the test page (http://strafford.org/newsarchiveList.php) showing the error message. The code on it is:
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/usr/home/straffordrpc/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
// load records from 'notices_srpc'
list($notices_srpcRecords, $notices_srpcMetaData) = getRecords(array(
'tableName' => 'notices_srpc',
'loadUploads' => true,
'allowSearch' => false,
'where' => "`createdDate` < '".date('Y-m-d H:i:s', strtotime('-1 year'))."')"
));
So in summary, can you help me get a News Archive List page showing items over a) 6 months old and b) over 1 year old? (The client can choose which range they want.)
I am assuming that the same Detail page can be used with both the Current News items and with the Archived News items.
Thanks in advance, J
Note: this site Running CMSB 3.10 and PHP v7.1.15
By leo - April 24, 2018
Hi,
You can try replacing the where statement with the following and see if the error is still there:
'where' => "`createdDate` < '".date('Y-m-d H:i:s', strtotime('-1 year'))."'"
Let me know if this works!
Thanks,
interactivetools.com
By jreddigital - May 2, 2018
Hi Leo, Glad to have you on board.
Your code worked, thank you.
For the record, here is what I did for an automatic archive news item page and the detail page - the code below is for my LIST page.
// load records from 'notices_srpc'
list($notices_srpcRecords, $notices_srpcMetaData) = getRecords(array(
'tableName' => 'notices_srpc',
'loadUploads' => true,
'allowSearch' => false,
'ignoreRemoveDate' => true,
'where' => "`publishDate` < '".date('Y-m-d H:i:s', strtotime('-1 year'))."'"
));
Then, in order to be able to use the same Detail page as my current news listings, I used this code for the detail page. The key was to use the ignoreRemoveDate. This is the active page http://strafford.org/newsarchiveList.php
list($notices_srpcRecords, $notices_srpcMetaData) = getRecords(array(
'tableName' => 'notices_srpc',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
'ignoreRemoveDate' => true,
));
$notices_srpcRecord = @$notices_srpcRecords[0]; // get first record