PDA

View Full Version : blog linked to dreamweaver automatically updates?


paulprice85
04-21-2010, 02:06 AM
Hello all, would appreciate your help as I can't find much info on this, that explains exactly what to do.

I have an account with blogger.com and want to have a blog page on my site which dynamically updates when I add posts on blogger.com.

I understand this can be done but don't know what I need to do. Is there a file I need to use like an .xml or something which communicates with some code on my sites html document?

Just need to clear up the basic process (and if anyone is familiar with blogger.com that'd be a bonus!)

Thanks to anyone who can help

cheers

Paul

gentleone
04-21-2010, 05:07 AM
I'm not familiar with blogger.com, but if there is a RSS feed option than you can parse your posts/feeds with PHP or JavaScript (jQuery) into your website.

paulprice85
04-21-2010, 08:23 AM
I'd be amazed if they didn't do RSS feeds but i'll make sure.

I'm pretty new to web design and illiterate with JavaScript. Is jQuery a library which contains all the JavaScript I'd ever need? I'd really appreciate it if you or anyone could point me in the right direction of where to get the code, and/or which code to use, to receive the RSS feed because I have no clue!

Thanks for your help, I appreciate it.

Paul

gentleone
04-21-2010, 01:10 PM
If you can with blogger than:

PHP: http://www.finalwebsites.com/snippets.php?id=49
jQuery: http://jparse.kylerush.net/demo

paulprice85
04-21-2010, 11:55 PM
thanks for that, I think it's the PHP I'm after here.

Could you please point me in the direction of how to go about using this code (thanks for that gentleone)

Which fields do I edit, and how does my html dreamweaver doc communicate with it? Sorry to ask a lot of questions but I'm no coder!
Just not sure where to put this code. Ie, internal, external, top of page, in the body etc.

Thanks

gentleone
04-22-2010, 06:46 AM
Just place the whole PHP snippet (or use PHP include) where you want the feed to appear on your page.

As you can see in the snippet it will parse a div (#rrsbox) and in that div the feed is organized with an unordered list. So don't place the snippet in another div, just use #rrsbox to position it in your CSS where you want it to appear on your page. Than you can style the unordered list in your CSS so that it has the look and feel of your overall design.

#rssbox {styles here)
#rssbox ul {styles here}
#rssbox ul li {styles here}
#rssbox a:link {styles here}
#rssbox a:visited {styles here}
#rssbox a:hover {styles here}
#rssbox a:active {styles here}
At the top part you see a string
$string = file_get_contents('http://www.web-development-blog.com/feed/');Change that url to the url of your feed from blogger and your done. This snippet will automatically create a cache folder on your server to lower the server load on the host where the RSS feed is hosted.

paulprice85
04-27-2010, 04:50 AM
Thats great! I'll get straight on it :-)

paulprice85
04-27-2010, 06:30 AM
Hi its me again (already). Just got a couple more questions for you. Please see the code below to see if it looks ok to you (just altered the source of the blog like you said). I take it I put this code where I want the blog to appear on the page? And I take it I remove the wordpress part? I created the rssbox rules you suggested on the top part of my page. Should I take it the blog will not appear on the page until it is live? As when I preview in the browser the page is blank (ie, no blog)

Thanks so much for being patient with me!

<?php
$cache_time = 3600*24; // 24 hours

$cache_file = $_SERVER['DOCUMENT_ROOT'].'/cache/test.rss';
$timedif = @(time() - filemtime($cache_file));

if (file_exists($cache_file) && $timedif < $cache_time) {
$string = file_get_contents($cache_file);
} else {
$string = file_get_contents('http://pipkorea.blogspot.com/');
if ($f = @fopen($cache_file, 'w')) {
fwrite ($f, $string, strlen($string));
fclose($f);
}
}
$xml = simplexml_load_string($string);

// place the code below somewhere in your html //


echo '

<div id="rssbox"> // is this DivID ok? as its not colored the same as others in document?
<ul>';
$count = 0;
$max = 3;

echo '


</ul>
</div>';
?>

gentleone
04-27-2010, 06:59 AM
There are 2 things!

The feed url should be:
http://pipkorea.blogspot.com/feeds/posts/default

And in the PHP script I don't see that you parse the feed in div #rssbox. You shouldn't take that part out otherwise no feed ;)


<div id="rssbox">
<ul>';
$count = 0;
$max = 3;
// the next object is an example for a feed from wordpress
foreach ($xml->channel->item as $val) {
if ($count < $max) {
echo '
<li>
<strong>'.$val->title.'</strong><br />
'.$val->description.' | <a href="'.$val->link.'">More &gt;</a>
</li>';
}
$count++;
}
echo '
</ul>
</div>';

paulprice85
04-27-2010, 08:20 AM
Hi gentleone, when I put in that extra bit of code...

foreach ($xml->channel->item as $val) {
if ($count < $max) {
echo '
<li>
<strong>'.$val->title.'</strong><br />
'.$val->description.' | <a href="'.$val->link.'">More &gt;</a>
</li>';
}
$count++;
}

Its black text like its inactive and the code literally shows up on the design view of the page. Just to make sure do I put all the code from http://www.finalwebsites.com/snippets.php?id=49 at that same point on the page?

Thanks for helping me by the way

gentleone
04-27-2010, 10:48 AM
Yes the whole code from <?php untill ?>. Put it where you want the feed to appear and then style it with CSS.