business of the day rss help required please

4 posts by 3 authors in: Forums > CMS Builder
Last Post: January 10, 2019   (RSS)

By willydoit - January 8, 2019

Hi all,

I have created a rss feed to select a random business as the business of the day, the idea being that I want to create an IFTTT applet to post the rss feed to a facebook page once a day

I can get everything working so far as the rss page and the IFTT side of things however I only want the business-of-day-rss.php to run once a day, I dont want the content to change each time the page is accessed.

How can I achieve it so that;

a) The page is automatically run at a specific time each day?

b) once run the page values stay the same until the page is recreated by the above schedule

I have included an example of my rss code below in case it helps.

Thanks in advance for any help provided.



  // load records from 'advertisers'
  list($advertisersRecords, $advertisersMetaData) = getRecords(array(
    'tableName'   => 'advertisers',
    'limit'       => '1',
    'orderBy'     => 'RAND()',
    'loadUploads' => false,
    'allowSearch' => false,
	  'where' => 'listing LIKE "%Standard Listing%"',
  ));

?>
<?PHP
function maxWords($textOrHtml, $maxWords) {
$text=str_replace("<p>","*P*",$textOrHtml);
$text= str_replace("</p>","*/P*",$text);
$text = strip_tags($text);
$words = preg_split("/\s+/", $text, $maxWords+1);
if (count($words) > $maxWords) { unset($words[$maxWords]); }
$output = join(' ', $words);
$output=str_replace("*P*","<p>",$output);
$output=str_replace("*/P*","</p>",$output);
$output.="...</p>";

return $output;
}
?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Business of the Day</title>
    <link>https://www.mysite.net</link>
    <description>Business of the Day</description>
    <pubDate><?php echo date('r') ?></pubDate>
    <language>en-us</language>

    <?php foreach ($advertisersRecords as $record): ?>
    <item>
      <title><?php echo htmlencode($record['title']) ?></title>
      <link>https://<?php echo $_SERVER['HTTP_HOST']; ?>/<?php echo $record['_link'] ?></link>
      <description>  <![CDATA[<?php echo maxWords ($record['description'],60) ?><br> <a href="http://<?php echo $_SERVER['HTTP_HOST']; ?>/<?php echo $record['_link'] ?>" target="_blank"> Read more..</a>]]></description>
      <pubDate><?php echo date('r', strtotime($record['createdDate'])) ?></pubDate>
      
    </item>
    <?php endforeach ?>
  </channel>
</rss>

By gkornbluth - January 9, 2019

Hi Willydoit,

Is it possible that using Daniel's approach triggered once a day by a cron job would be a direction worth exploring?

I've got a recipe in my CMSB Cookbook that uses a cron job to trigger the sending of emails if certain criteria are met.

It might easily be modified to do what you need.

http://www.thecmsbcookbook.com/recipedetail.php?SENDING-MEMBERSHIP-REMINDER-EMAILS-USING-A-CRON-JOB-471

Best,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By willydoit - January 10, 2019

Hi Jerry,

not being a programmer I have used the cookbook for a number of solutions over the years, I will take a look and see if it could be adapted by someone with my knowledge level which is pretty much cut and paste and hope for the best :-)