Show images in RSS feed / Also limited description length

13 posts by 6 authors in: Forums > CMS Builder
Last Post: September 10, 2010   (RSS)

By gadefgaertgqe - February 2, 2010 - edited: February 2, 2010

Hi There,

I am using your excellent 'Basic auto' template and have everything working including an RSS feed of the used bikes (as per instructions http://www.interactivetools.com/docs/cmsbuilder/rss_feeds.html).

However, there are 2 things I would like to be able to do:

1 - It is important for me to have an image with each item listed. I have tried all sorts of stuff but can't get it working. I know that I am very close as after following these instructions: http://www.interactivetools.com/docs/cmsbuilder/uploads.html) I can see the correct URL in the source! For some reason though it just isn't doing the last bit lol!

2 - Also is it possible to limit the length of a description to a certain amount of characters?

Many thanks in advance

8BG

Re: [gkornbluth] Show images in RSS feed / Also limited description length

By gadefgaertgqe - February 9, 2010

That worked great! Thanks! :)

Re: [gkornbluth] Show images in RSS feed / Also limited description length

By rez - March 30, 2010

I am using the wysiwyg editor with barely any formatting at all but i do have several paragraphs. Limiting the words is making it all one paragraph. How can I keep my paragraphs?

Re: [rez] Show images in RSS feed / Also limited description length

By gkornbluth - March 31, 2010

Hi rez,

Do you mean makes it all one paragraph on the list page that is limited or on the detail page?

What does the source code look like with and without the limit words function?

Best,

Jerry
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

Re: [gkornbluth] Show images in RSS feed / Also limited description length

By Jason - March 31, 2010

Hi rez,

Use this version of maxWords to keep your paragraph formatting.
<?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;
}
?>



Let me know if that works for you.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Show images in RSS feed / Also limited description length

By dakrusha - September 10, 2010

i'm not getting this to work.
can somebody post a sample of where it is in the code?

thx
tim

Re: [dakrusha] Show images in RSS feed / Also limited description length

By Jason - September 10, 2010

Hi Tim,

What is the nature of the problem you're encountering? If you could clarify what's happening and attach the .php file you're working with, I can take a look for you.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Show images in RSS feed / Also limited description length

By dakrusha - September 10, 2010

it's not cutting down the amount of text displayed.
i'm sure i've done some thing wrong just not sure what.


<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/hermes/bosweb/web251/b2519/sl.evsmc/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
list($about_usRecords, $about_usMetaData) = getRecords(array(
'tableName' => 'about_us',
));

?>

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

return $output;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>About EVS</title>
<style type="text/css">
<!--
body {
font-family: Verdana; background-image: url(http://www.equinevetspecialists.com/images/evs_background.jpg);
}

-->
</style></head>

<body>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><?php include 'header1.php'; ?></td>
</tr>
<tr>
<td align="center"><?php include 'menu.php'; ?></td>
</tr>
<tr>
<td><table width="972" border="0" cellspacing="0" cellpadding="0" background="http://www.equinevetspecialists.com/images/body_bg.jpg">
<tr>
<td><table width="972" border="0" cellspacing="5" cellpadding="0">
<tr>
<td height="700" valign="top">



<?php foreach ($about_usRecords as $record): ?>


<?php echo $record['content'] ?><br/>
<a href="<?php echo $record['_link'] ?>">Read More</a><br/>



<?php foreach ($record['images'] as $upload): ?>
<?PHP echo maxWords($record['content'], 5); ?>


<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>

<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>

<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/>

<?php endif ?>
<?php endforeach ?>
<!-- STEP2a: /Display Uploads -->


<hr/>

<?php endforeach ?>
<?php if (!$about_usRecords): ?>
No records were found!<br/><br/>
<?php endif ?>





</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td align="center"><?php include 'footer.php'; ?></td>
</tr>
</table>
</body>
</html>

Re: [dakrusha] Show images in RSS feed / Also limited description length

By Jason - September 10, 2010

Hi,

What's happening is that you're outputting the content of your about record in two different places:
<?php foreach ($about_usRecords as $record): ?>


<?php echo $record['content'] ?><br/>
<a href="<?php echo $record['_link'] ?>">Read More</a><br/>



<?php foreach ($record['images'] as $upload): ?>
<?PHP echo maxWords($record['content'], 5); ?>


You're only using the maxWords function the second time. Trying changing the code to this:
<?php foreach ($about_usRecords as $record): ?>


<?php echo maxWords($record['content'],5); ?><br/>
<a href="<?php echo $record['_link'] ?>">Read More</a><br/>


<?php foreach ($record['images'] as $upload): ?>


Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/