Postagens recentes no blog
Autor: Wendel Gomes | Publicado: 2012-08-01T20:25:00-03:00







Deixe seus leitores informados das postagens mais recentes do seu blog. Com esse Gadget que mostra as postagens mais recentes,&nbsp;comentários&nbsp;e data.

Vamos ao tutorial.

1º Passo: Abra o Painel do seu Blogger, Layout, Adicionar um Gadget-Html/JavaScript.&nbsp;
De um titulo e cole esse&nbsp;código:


&lt;style type='text/css'&gt;

img.recent_thumb {padding:2px;width:70px;height:70px;border:0;

float:left;margin:5px 10px 10px 0; border: 1px solid #ccc;}

.recent_posts_with_thumbs {float: left;width: 100%;min-height: 100px;margin: 0px 0px 5px 0px;padding: 0;font-size:12px;}

ul.recent_posts_with_thumbs li {padding-bottom:5px;padding-top:5px;min-height:75px;}

.recent_posts_with_thumbs a {text-decoration:none;}

.recent_posts_with_thumbs strong {font-size:10px;}

.recent_posts_with_thumbs h4 {

text-transform: uppercase;

font-size: 14px;

}

&lt;/style&gt;

&lt;script type='text/javascript'&gt;

//&lt;![CDATA[

function showrecentpostswiththumbs(json) {document.write('&lt;ul class="recent_posts_with_thumbs"&gt;'); for (var i = 0; i &lt; numposts; i++) {var entry = json.feed.entry[i];var posttitle = entry.title.$t;var posturl;if (i == json.feed.entry.length) break;for (var k = 0; k &lt; entry.link.length;k++){

if(entry.link[k].rel=='replies'&amp;&amp;entry.link[k].type=='text/html'){var commenttext=entry.link[k].title;var commenturl=entry.link[k].href;}

if (entry.link[k].rel == 'alternate') {posturl = entry.link[k].href;break;}}var thumburl;try {thumburl=entry.media$thumbnail.url;}catch (error)



{

s=entry.content.$t;a=s.indexOf("&lt;img");b=s.indexOf("src=\"",a);c=s.indexOf("\"",b+5);d=s.substr(b+5,c-b-5);if((a!=-1)&amp;&amp;(b!=-1)&amp;&amp;(c!=-1)&amp;&amp;(d!="")){

thumburl=d;} else thumburl='http://i48.tinypic.com/73jsjr.gif';

}



var postdate = entry.published.$t;var cdyear = postdate.substring(0,4);var cdmonth = postdate.substring(5,7);var cdday = postdate.substring(8,10);var monthnames = new Array();monthnames[1] = "Jan";monthnames[2] = "Fev";monthnames[3] = "Mar";monthnames[4] = "Abr";monthnames[5] = "Maio";monthnames[6] = "Jun";monthnames[7] = "Jul";monthnames[8] = "Ago";monthnames[9] = "Set";monthnames[10] = "Out";monthnames[11] = "Nov";monthnames[12] = "Dez";document.write('&lt;li class="clearfix"&gt;');





if(showpostthumbnails==true)&nbsp;

document.write('&lt;img class="recent_thumb" src="'+thumburl+'"/&gt;');

document.write('&lt;b&gt;&lt;h4&gt;&lt;a href="'+posturl+'" target ="_top"&gt;'+posttitle+'&lt;/a&gt;&lt;/b&gt;&lt;/h4&gt;');



&nbsp; &nbsp; if ("content" in entry) {

&nbsp; &nbsp; &nbsp; var postcontent = entry.content.$t;}

&nbsp; &nbsp; else

&nbsp; &nbsp; if ("summary" in entry) {

&nbsp; &nbsp; &nbsp; var postcontent = entry.summary.$t;}

&nbsp; &nbsp; else var postcontent = "";

&nbsp; &nbsp; var re = /&lt;\S[^&gt;]*&gt;/g;&nbsp;

&nbsp; &nbsp; postcontent = postcontent.replace(re, "");





if (showpostsummary == true) {



&nbsp; &nbsp; &nbsp; if (postcontent.length &lt; numchars) {

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.write('&lt;i&gt;');

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.write(postcontent);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.write('&lt;/i&gt;');}

&nbsp; &nbsp; &nbsp; else {

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.write('&lt;i&gt;');

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;postcontent = postcontent.substring(0, numchars);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var quoteEnd = postcontent.lastIndexOf(" ");

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;postcontent = postcontent.substring(0,quoteEnd);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.write(postcontent + '...');

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.write('&lt;/i&gt;');}

}



var towrite='';var flag=0;

document.write('&lt;br&gt;&lt;strong&gt;');



if(showpostdate==true) {towrite=towrite+monthnames[parseInt(cdmonth,10)]+' - '+cdday+' - '+cdyear;flag=1;}



if(showcommentnum==true)&nbsp;

{

if (flag==1) {towrite=towrite+' | ';}

if(commenttext=='0 Comments') commenttext='0 comentarios';

if(commenttext=='1 Comment') commenttext='1 comentario';

commenttext = '&lt;a href="'+commenturl+'" target ="_top"&gt;'+commenttext+'&lt;/a&gt;';

towrite=towrite+commenttext;

flag=1;

;

}



if(displaymore==true)&nbsp;

{

if (flag==1) towrite=towrite+' | ';

towrite=towrite+'&lt;a href="'+posturl+'" class="url" target ="_top"&gt;Leia mais&lt;/a&gt;';

flag=1;

;

}



document.write(towrite);



document.write('&lt;/strong&gt;&lt;/li&gt;');

if(displayseparator==true)&nbsp;

if (i!=(numposts-1))

document.write('');

}document.write('&lt;/ul&gt;');



}

//]]&gt;

&lt;/script&gt;

&lt;script style='text/javascript'&gt;

var numposts = 5;

var showpostthumbnails = true;

var displaymore = true;

var displayseparator = true;

var showcommentnum = true;

var showpostdate = true;

var showpostsummary = true;

var numchars = 80;&lt;/script&gt;

&lt;script src='http://NOMEDOSEUBLOG.blogspot.com/feeds/posts/default?orderby=published&amp;alt=json-in-script&amp;callback=showrecentpostswiththumbs'&gt;&lt;/script&gt;


Substutua a linha&nbsp;NOMEDOSEUBLOG&nbsp;pelo nome do seu blog, deixe tudo junto não de espaço.&nbsp;
Agora é só salvar e ver o resultado.




&nbsp;Obrigado por ler o artigo, até o&nbsp;próximo!