RSS Feed with Photo

4 posts by 2 authors in: Forums > CMS Builder
Last Post: April 13, 2020   (RSS)

I am trying to add a Photo to my RSS Feed and I am asking for some assistance please.

Here is the code generated from my CMS Admin:

<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/tcfs/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 'gallery'
list($galleryRecords, $galleryMetaData) = getRecords(array(
'tableName' => 'gallery',
'orderBy' => '', // use default database order
'loadUploads' => false,
'allowSearch' => false,
));

?>
<?php header('Content-type: application/xml; charset=utf-8'); ?><?php echo '<'.'?xml version="1.0" encoding="UTF-8"?>'; ?>
<rss version="2.0">
<channel>
<title>Name of your site or RSS feed</title>
<link>http://www.example.com/</link>
<description>Your site description goes here</description>
<pubDate><?php echo date('r') ?></pubDate>
<language>en-us</language>

<?php foreach ($galleryRecords as $record): ?>
<item>
<title><?php echo htmlencode($record['title']) ?></title>
<link>http://<?php echo $_SERVER['HTTP_HOST']; ?>/<?php echo $record['_link'] ?></link>
<description><![CDATA[<?php echo $record['title'] ?>]]></description>
<pubDate><?php echo date('r', strtotime($record['createdDate'])) ?></pubDate>
<guid isPermaLink="false"><?php echo $record['_link'] ?></guid>
</item>
<?php endforeach ?>
</channel>
</rss>

http://trinicarsforsale.com/mobiletest.php

<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
  
  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('/home/tcfs/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 'featured_cars'
  list($featured_carsRecords, $featured_carsMetaData) = getRecords(array(
    'tableName'   => 'featured_cars',
    'orderBy'     => '',   // use default database order
    'loadUploads' => true,
    'allowSearch' => false,
	 'perPage'    => '20',
  ));

?>

<?php header('Content-type: application/xml; charset=utf-8'); ?><?php echo '<'.'?xml version="1.0" encoding="UTF-8"?>'; ?>
<rss version="2.0">
  <channel>
    <title>Name of your site or RSS feed</title>
    <link>http://www.example.com/</link>
    <description>Your site description goes here</description>
    <pubDate><?php echo date('r') ?></pubDate>
    <language>en-us</language>

    <?php foreach ($featured_carsRecords as $record): ?>
    <item>
      <title><?php echo htmlencode($record['main_id']) ?></title>
      <link>http://<?php echo $_SERVER['HTTP_HOST']; ?>/<?php echo $record['_link'] ?></link>
      <description><![CDATA[<?php echo $record['make_of_car'] ?>]]></description>
      <pubDate><?php echo date('r', strtotime($record['createdDate'])) ?></pubDate>
      <guid isPermaLink="false"><?php echo $record['_link'] ?></guid>
	<?php foreach ($record['main_photo'] as $index => $upload): ?>
      <?php if ($index >= 1) { continue; } // limit uploads shown ?>
      <media:content url="https://<?php echo $_SERVER['HTTP_HOST']; ?><?php echo htmlencode($upload['urlPath']) ?>" medium="image" />
    <?php endforeach ?> 
    </item>
    <?php endforeach ?>
  </channel>
</rss>

By Steve99 - April 13, 2020

You'll want to remove the blank line before your "header content type" line.
Or you can modify php output buffering settings as Dave described here: https://www.interactivetools.com/forum/forum-posts.php?postNum=2243220#post2243220

I'm assuming that's likely what the "An unexpected error occurred" was for.