구글 블로거(blogger) 랜덤 글 표시하는 가젯, 위젯 gadget

구글 블로거(Blogger)에 적용할 수 있는 템플릿은 매우 많다.

템플릿(테마) 모음 사이트 : https://gooyaabitemplates.com/

하지만, '무료' 템플릿인 경우, 랜덤 글(Random Posts) 위젯 기능이 안되는 것도 있다.

아래 스크립트를 추가하면, 랜덤 글을 표시할 수 있다.


블로거 - 레이아웃 메뉴에서 '가젯 추가'

가젯 추가


HTML/자바스크립트 를 선택한다.

콘텐츠 부분에, 아래의 스크립트를 추가 후, 저장하면 된다.


<ul id='random-posts'>
<script type='text/javaScript'>
var tow_numposts=5;
var tow_snippet_length=150;
var tow_info='yes';
var tow_comment='Comments';
var tow_disable='Comments Disabled';
var tow_current=[];var tow_total_posts=0;var tow_current=new Array(tow_numposts);function totalposts(json){tow_total_posts=json.feed.openSearch$totalResults.$t}document.write('<script type=\\"text/javascript\\" src=\\"/feeds/posts/default?alt=json-in-script&max-results=0&callback=totalposts\\"><\\/script>');function getvalue(){for(var i=0;i<tow_numposts;i++){var found=false;var rndValue=get_random();for(var j=0;j<tow_current.length;j++){if(tow_current[j]==rndValue){found=true;break}};if(found){i--}else{tow_current[i]=rndValue}}};function get_random(){var ranNum=1+Math.round(Math.random()*(tow_total_posts-1));return ranNum};
</script>
<script type='text/javaScript'>
function random_posts(json){for(var i=0;i<tow_numposts;i++){var entry=json.feed.entry[i];var tow_posttitle=entry.title.$t;if('content'in entry){var tow_get_snippet=entry.content.$t}else{if('summary'in entry){var tow_get_snippet=entry.summary.$t}else{var tow_get_snippet="";}};tow_get_snippet=tow_get_snippet.replace(/<[^>]*>/g,"");if(tow_get_snippet.length<tow_snippet_length){var tow_snippet=tow_get_snippet}else{tow_get_snippet=tow_get_snippet.substring(0,tow_snippet_length);var space=tow_get_snippet.lastIndexOf(" ");tow_snippet=tow_get_snippet.substring(0,space)+"…";};for(var j=0;j<entry.link.length;j++){if('thr$total'in entry){var tow_commentsNum=entry.thr$total.$t+' '+tow_comment}else{tow_commentsNum=tow_disable};if(entry.link[j].rel=='alternate'){var tow_posturl=entry.link[j].href;var tow_postdate=entry.published.$t;if('media$thumbnail'in entry){var tow_thumb=entry.media$thumbnail.url}else{tow_thumb="<http://2.bp.blogspot.com/-XQt2v4x5dl8/T1zdpFh392I/AAAAAAAABUU/xMJZDedw38k/s1600/default.jpg>"}}};document.write('<li>');document.write('<img alt="'+tow_posttitle+'" src="'+tow_thumb+'"/>');document.write('<div><a href="'+tow_posturl+'" rel="nofollow" title="'+tow_snippet+'">'+tow_posttitle+'</a></div>');if(tow_info=='yes'){document.write('<span>'+tow_postdate.substring(8,10)+'/'+tow_postdate.substring(5,7)+'/'+tow_postdate.substring(0,4)+' - '+tow_commentsNum)+'</span>'}document.write('<div style="clear:both"></div></li>')}};getvalue();for(var i=0;i<tow_numposts;i++){document.write('<script type=\\"text/javascript\\" src=\\"/feeds/posts/default?alt=json-in-script&start-index='+tow_current[i]+'&max-results=1&callback=random_posts\\"><\\/script>')};
</script>
</ul>
<style type='text/css'>
#random-posts img{float:left;margin-right:10px;border:1px solid #999;background:#FFF;width:100px;height:100px;padding:3px}
#random-posts li{margin: 0px 0px 10px 0px;}
</style>

2015년의 옛날 글도 랜덤하게 표시가 된다.

랜덤 글 표시 샘플





본문 Written by dukgun.com

Post a Comment

다음 이전