웹마스터 팁

<html>
<head>
<title>타이틀</title>

<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAdV0OihhLfo4ru8N1BXzlWxSJ87f2VNqmObhB7kj4DJwDOGkiiBR3Nh79Pxxmk0DgEb3TTwZHI-Fp1g"></script>
<script type="text/javascript" src="js스크립트 하단참조"></script>
<style type="text/css">
.labelfield{ /*CSS for label field in general*/
color:brown;
font-size: 90%;
}

.datefield{ /*CSS for date field in general*/
color:gray;
font-size: 90%;
}

#example1 li{ /*CSS specific to demo 1*/
margin-bottom: 4px;
}

#example2 div{ /*CSS specific to demo 2*/
margin-bottom: 5px;
}

#example2 div a{ /*CSS specific to demo 2*/
text-decoration: none;
}

#example3 a{ /*CSS specific to demo 3*/
color: #D80101;
text-decoration: none;
font-weight: bold;
}

#example3 p{ /*CSS specific to demo 3*/
margin-bottom: 2px;
}

code{ /*CSS for insructions*/
color: red;
}
</style>
</head>
</body>


<b>Example 1: (Single RSS feed, 10 entries, "<code>date</code>" field enabled, sort by <code>title</code>)</b><p>
<a href="javascript:cssfeed.init()"><B>본 항목을 새로고침</B></a>

<script type="text/javascript">
var cssfeed=new gfeedfetcher("example1", "example1class", "")
cssfeed.addFeed("문화일보", "http://news.naver.com/rss/rss_presscenter.nhn?office_id=021") //RSS주소 및 제목
cssfeed.displayoptions("date") //날짜 필드 보여주기
cssfeed.setentrycontainer("li") //정렬은 Li태그로
cssfeed.filterfeed(10, "title") //목록은 10개
cssfeed.init() //Always call this last
</script>




<b>Example 2: (Two RSS feeds, 6 entries, "<code>label"</code>, "<code>datetime</code>", and "<code>snippet</code>" fields enabled, sort by <code>label</code>)</b><p>
<a href="javascript:socialfeed.init()"><B>본 항목을 새로고침</B></a>

<script type="text/javascript">
var socialfeed=new gfeedfetcher("example2", "example2class", "_new")
socialfeed.addFeed("동아일보", "http://news.naver.com/rss/rss_presscenter.nhn?office_id=020") //Specify "label" plus URL to RSS feed
socialfeed.addFeed("조선일보", "http://news.naver.com/rss/rss_presscenter.nhn?office_id=023") //Specify "label" plus URL to RSS feed
socialfeed.displayoptions("label datetime snippet") //show the specified additional fields
socialfeed.setentrycontainer("div") //Display each entry as a DIV
socialfeed.filterfeed(6, "label") //Show 6 entries, sort by label
socialfeed.init() //Always call this last
</script>






<b>Example 3: (Three RSS feeds, 8 entries, "<code>datetime</code>" and "<code>snippet</code>" fields enabled, sort by <code>date</code>)</b><p>
<a href="javascript:newsfeed.init()"><B>본 항목을 새로고침</B></a>


<script type="text/javascript">
var newsfeed=new gfeedfetcher("example3", "example3class", "_new")
newsfeed.addFeed("서울신문", "http://news.naver.com/rss/rss_presscenter.nhn?office_id=081") //Specify "label" plus URL to RSS feed
newsfeed.addFeed("한겨레", "http://news.naver.com/rss/rss_presscenter.nhn?office_id=028") //Specify "label" plus URL to RSS feed
newsfeed.addFeed("중앙일보", "http://news.naver.com/rss/rss_presscenter.nhn?office_id=025") //Specify "label" plus URL to RSS feed
newsfeed.displayoptions("datetime snippet") //show the specified additional fields
newsfeed.setentrycontainer("p") //Display each entry as a paragraph
newsfeed.filterfeed(8, "date") //Show 8 entries, sort by date
newsfeed.init() //Always call this last
</script>


</body>
</html>

js스크립트 
var gfeedfetcher_loading_image="loading" //Full URL to "loading" image. No need to config after this line!!

google.load("feeds", "1") //Load Google Ajax Feed API (version 1)

function gfeedfetcher(divid, divClass, linktarget){
this.linktarget=linktarget || "" //link target of RSS entries
this.feedlabels=[] //array holding lables for each RSS feed
this.feedurls=[]
this.feeds=[] //array holding combined RSS feeds' entries from Feed API (result.feed.entries)
this.feedsfetched=0 //number of feeds fetched
this.feedlimit=5
this.showoptions="" //Optional components of RSS entry to show (none by default)
this.sortstring="date" //sort by "date" by default
document.write('<div id="'+divid+'" class="'+divClass+'"></div>') //output div to contain RSS entries
this.feedcontainer=document.getElementById(divid)
this.itemcontainer="<li>" //default element wrapping around each RSS entry item
}

gfeedfetcher.prototype.addFeed=function(label, url){
this.feedlabels[this.feedlabels.length]=label
this.feedurls[this.feedurls.length]=url
}

gfeedfetcher.prototype.filterfeed=function(feedlimit, sortstr){
this.feedlimit=feedlimit
if (typeof sortstr!="undefined")
this.sortstring=sortstr
}

gfeedfetcher.prototype.displayoptions=function(parts){
this.showoptions=parts //set RSS entry options to show ("date, datetime, time, snippet, label, description")
}

gfeedfetcher.prototype.setentrycontainer=function(containerstr){  //set element that should wrap around each RSS entry item
this.itemcontainer="<"+containerstr.toLowerCase()+">"
}

gfeedfetcher.prototype.init=function(){
this.feedsfetched=0 //reset number of feeds fetched to 0 (in case init() is called more than once)
this.feeds=[] //reset feeds[] array to empty (in case init() is called more than once)
this.feedcontainer.innerHTML='<img src="'+gfeedfetcher_loading_image+'" /> Retrieving RSS feed(s)'
var displayer=this
for (var i=0; i<this.feedurls.length; i++){ //loop through the specified RSS feeds' URLs
var feedpointer=new google.feeds.Feed(this.feedurls[i]) //create new instance of Google Ajax Feed API
var items_to_show=(this.feedlimit<=this.feedurls.length)? 1 : Math.floor(this.feedlimit/this.feedurls.length) //Calculate # of entries to show for each RSS feed
if (this.feedlimit%this.feedurls.length>0 && this.feedlimit>this.feedurls.length && i==this.feedurls.length-1) //If this is the last RSS feed, and feedlimit/feedurls.length yields a remainder
items_to_show+=(this.feedlimit%this.feedurls.length) //Add that remainder to the number of entries to show for last RSS feed
feedpointer.setNumEntries(items_to_show) //set number of items to display
feedpointer.load(function(r){displayer._fetch_data_as_array(r)}) //call Feed.load() to retrieve and output RSS feed
}
}


gfeedfetcher._formatdate=function(datestr, showoptions){
var itemdate=new Date(datestr)
var parseddate=(showoptions.indexOf("datetime")!=-1)? itemdate.toLocaleString() : (showoptions.indexOf("date")!=-1)? itemdate.toLocaleDateString() : (showoptions.indexOf("time")!=-1)? itemdate.toLocaleTimeString() : ""
return "<span class='datefield'>"+parseddate+"</span>"
}

gfeedfetcher._sortarray=function(arr, sortstr){
var sortstr=(sortstr=="label")? "ddlabel" : sortstr //change "label" string (if entered) to "ddlabel" instead, for internal use
if (sortstr=="title" || sortstr=="ddlabel"){ //sort array by "title" or "ddlabel" property of RSS feed entries[]
arr.sort(function(a,b){
var fielda=a[sortstr].toLowerCase()
var fieldb=b[sortstr].toLowerCase()
return (fielda<fieldb)? -1 : (fielda>fieldb)? 1 : 0
})
}
else{ //else, sort by "publishedDate" property (using error handling, as "publishedDate" may not be a valid date str if an error has occured while getting feed
try{
arr.sort(function(a,b){return new Date(b.publishedDate)-new Date(a.publishedDate)})
}
catch(err){}
}
}

gfeedfetcher.prototype._fetch_data_as_array=function(result){
var thisfeed=(!result.error)? result.feed.entries : "" //get all feed entries as a JSON array or "" if failed
if (thisfeed=="") //if error has occured fetching feed
alert("Google Feed API Error: "+result.error.message)
for (var i=0; i<thisfeed.length; i++) //For each entry within feed
result.feed.entries[i].ddlabel=this.feedlabels[this.feedsfetched] //extend it with a "ddlabel" property
this.feeds=this.feeds.concat(thisfeed) //add entry to array holding all feed entries
this._signaldownloadcomplete() //signal the retrieval of this feed as complete (and move on to next one if defined)
}

gfeedfetcher.prototype._signaldownloadcomplete=function(){
this.feedsfetched+=1
if (this.feedsfetched==this.feedurls.length) //if all feeds fetched
this._displayresult(this.feeds) //display results
}


gfeedfetcher.prototype._displayresult=function(feeds){
var rssoutput=(this.itemcontainer=="<li>")? "<ul>\n" : ""
gfeedfetcher._sortarray(feeds, this.sortstring)
for (var i=0; i<feeds.length; i++){
var itemtitle="<a href=\"" + feeds[i].link + "\" target=\"" + this.linktarget + "\" class=\"titlefield\">" + feeds[i].title + "</a>"
var itemlabel=/label/i.test(this.showoptions)? '<span class="labelfield">['+this.feeds[i].ddlabel+']</span>' : " "
var itemdate=gfeedfetcher._formatdate(feeds[i].publishedDate, this.showoptions)
var itemdescription=/description/i.test(this.showoptions)? "<br />"+feeds[i].content : /snippet/i.test(this.showoptions)? "<br />"+feeds[i].contentSnippet  : ""
rssoutput+=this.itemcontainer + itemtitle + " " + itemlabel + " " + itemdate + "\n" + itemdescription + this.itemcontainer.replace("<", "</") + "\n\n"
}
rssoutput+=(this.itemcontainer=="<li>")? "</ul>" : ""
this.feedcontainer.innerHTML=rssoutput
}

제목 글쓴이 날짜
PHP에 대한 소개 [216] zero 2000.03.06
[SocialXE] 1.7.4.x 업데이트 후 SocialXE에서 '잘못된 요청입니다.' 오류가 뜨는 문제 해결하기 [15] file TUW 2014.03.26
업글타일 모듈에서 fail_to_trash가 뜨지만 삭제는 정상으로 진행된다면 SeungXE 2014.10.11
댓글 삭제/수정/답글 시 팝업창으로 띄우기 [22] file 고진감래 2009.10.21
[10원팁] 한서버에 2개이상의 xe를 사용할때 간헐적 백지문제 [4] 키스미베이베 2014.09.19
XE 그룹아이콘 레벨아이콘 아이콘샵 동시출력하기(모르는분들 있으까봐올립니다.) [1] 모앱 2013.02.22
방화벽 때문에 쉬운설치가 안 될경우 해결법 빛의바다 2014.10.04
회원정보 손쉽게 엑셀 파일로 저장하기 [34] thejeon 2009.08.05
메시지톡 버튼 게시판에 넣기 [18] file 착한악마 2013.11.26
php에서 한글언어 작성이 깨질때 [1] 광개토대왕3 2014.06.28
구글 API 활용(뉴스가져오기) pixfine 2014.09.24
[AJAX]DB 해당값을 검색하기 pixfine 2014.09.24
330 오류(net::ERR_CONTENT_DECODING_FAILED): 알 수 없는 오류 - 해결책 [2] 하얀마법 2012.10.25
[업데이트] [Easy Tip] [XE 1.7] XE 코어 js, css파일 jsdelivr CDN사용하기 [13] file Typhoon 2014.08.28
회원 프로필 사진 리사이징될때 ratio가 아닌 crop으로 처리하기 mAKEkr 2014.09.19
레이아웃 작업 중 갑자기 files/faceOFF/xxx/ko.cache.php 에러 발생할 시 Novelic 2014.09.19
로그인 실패 관련 쪽지 또는 메일이 안 날라오게 하는 방법 [9] sejin7940 2012.11.12
셀과 색상의 조합이 특징인 테이블 구조 pixfine 2014.09.16
익스별 호출 모음...스타일(재탕이면 죄송)모은거는 못봐서요~ imagineshop 2014.09.16
머니시스템 보유머니 출력하기 [13] oscarmike 2014.04.24