Script & Style 是我和 Chris Coyier 创建的网站,博主和开发人员都可以在这里提交有关 CSS、XHTML、jQuery、MooTools 和其他网站设计和开发主题的文章。由于社区的热情和每天提交的优质文章数量,该网站的受欢迎程度持续增长。
我喜欢在我的网站上分享知识,网站启动后我做的第一件事就是在我的网站上获取提要,这样我就可以分享指向其他优质文章的链接。该过程仅用了 5 分钟。以下是将脚本和样式提要添加到您的网站的方法!
第 1 步:下载 SimplePie
SimplePie 是一个出色的提要读取 PHP 库,我们将使用它来抓取、读取和缓存 Script & Style 提要。单击此处访问 SimplePie 下载页面。
第 2 步:PHP 代码
//get teh simplepie library require_once('simplepie/simplepie.inc'); //grab the feed $feed = new SimplePie('http://feeds.feedburner.com/ScriptAndStyle'); //enable caching $feed->enable_cache(true); //provide the caching folder $feed->set_cache_location($_SERVER['DOCUMENT_ROOT'].'/cache'); //set the amount of seconds you want to cache the feed $feed->set_cache_duration(1800); //init the process $feed->init(); //let simplepie handle the content type (atom, RSS...) $feed->handle_content_type(); //load my own array -- i like my own arrays... for ($x = 0; $x < $feed->get_item_quantity(15); $x++) { $items[] = $feed->get_item($x); } //loop through each item foreach ($items as $item) { echo '<a href="',$item->get_link(),'" >',$item->get_title(),'</a>'; }
一旦您有 SimplePie 可用,请拉入 Script & Style 提要。您会注意到您想要启用缓存并提供一个缓存文件夹以保持您的站点高效。一旦您将每个项目放入 $items 数组中,您只需输出您最终将编写脚本和样式的 XHTML。您可以在我的网站 davidwalsh.name 和 Chris Coyier 的网站 CSS-Tricks.com 上查看示例。
就是这样!
将脚本和样式提要添加到您的网站是小菜一碟!好吧,感谢 SimplePie,这是小菜一碟。为您的 Script & Style 站点提要设置有趣的样式。完成后发布指向您网站的链接 – 我们很乐意看到您创建的内容!