Jump to content

spazz

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Everything posted by spazz

  1. Much appreciated! I will take a look and will report back with how I get on!
  2. I'm having real problems with a rss box that I'm trying to incorporate onto the homepage of our website... The code I'm using as a basis I got from here - http://www.dynamicdrive.com/dynamicindex18/rssdisplaybox/index.htm It worked okay displaying title, date and content, however, we wanted it to display the first image of the blog entry as well. In the outputbody.php (the file that dictates what is shown in the rss box) I incorporated this code (shown in bold EDIT: with the bold tags around it! ) - <?php //Function for ouputting the body of each RSS item displayed (inside loop)- DynamicDrive.com //For syntax pf bpdu, see: http://simplepie.org/docs/installation/from-scratch/ and http://simplepie.org/docs/reference/ //Function by default defines 3 different body outputs (templates). Modify or add additional templates as desired [b] function get_image($text) { $imageurl=""; preg_match('/<\s*img [^\>]*src\s*=\s*[\""\']?([^\""\'>]*)/i' , $text, $matches); $imageurl=$matches[1]; if (!$imageurl) { preg_match("/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/)([a-zA-Z0-9\-\_]{11})([^<\s]*)/", $text, $matches2); $youtubeurl = $matches2[0]; if ($youtubeurl) $imageurl = "http://i.ytimg.com/vi/{$matches2[3]}/1.jpg"; } return $imageurl; }[/b] function shortencontent($content, $len=40){ if(strlen($content) > $len){ return substr($content, 0, $len - 6) . ' . . .'; } else { return $content; } } function outputbody($item, $template=""){ if ($template=="" || $template=="default"){ //DEFAULT TEMPLATE ?> <div class="rsscontainer"> <div class="rsstitle"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></div> <div class="rssdate"><?php echo $item->get_date('d M Y g:i a'); ?></div> <div class="rssdescription"><?php echo shortencontent($item->get_description(), 400); ?></div> [b]<div class="rssimage"><?php echo get_image(); ?></div>[/b] </div> <?php } //end default template else if ($template=="titles"){ //"TITLES" TEMPLATE ?> <div class="rsscontainer"> <div class="rsstitle"><a href="<?php echo $item->get_permalink(); ?>" target="_new"><?php echo $item->get_title(); ?></a></div> <div>Category: <?php echo $item->get_category(); ?></div> </div> <?php } //end titles template else if ($template=="titlesdates"){ //"TITLESDATES" TEMPLATE ?> <div class="rsscontainer"> <span class="rsstitle"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></span> <span class="rssdate"><?php echo $item->get_date('m/d/y g:i a'); ?></span> </div> <?php } //end titlesdates template else if ($template=="mytemplatename"){ //"mytemplatename" TEMPLATE ?> //DEFINE ADDITIONAL CUSTOM TEMPLATE(s) USING SAME LOGIC STRUCTURE AS ABOVE //For syntax of template body, see SimplePie docs: http://simplepie.org/docs/installation/from-scratch/ and http://simplepie.org/docs/reference/ <?php } else die ("No template exists with such name!"); } //Closing function bracket ?> While it creates an imagebox nothing is shown and when you open the empty image box in the browser it displays the following URL - http://www.oururl.%20.%20.%20.</div>%20%20%20%20%20%20%20%20<div%20class= I have little PHP knowledge but don't really know where to start with this... please can anyone help or point me in the right direction. I appreciate that it is frustrating dealing with someone with limited knowledge but please have a little patience with me... Cheers people!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.