Resumo automático para posts do blog

Views:
CÓDIGO JAVASCRIPT
(colar acima de </head>)

<!-- JavaScript Posts Resumidos-->
<style type='text/css'>
.thumbnailimg IMG {
   max-width:auto;
   width: expression(this.width &gt; auto ? auto: true);
   max-height:auto;
   height: expression(this.height &gt; auto ? auto: true);
}
</style>
<script type='text/javascript'>
var thumbnail_mode = &quot;no-float&quot; ;
var classicMode = false ;
var summary_noimg = 100;
var summary_img = 30;
var indent = 3;
</script>
<script type='text/javascript'>
//<![CDATA[
function stripHtmlTags(s,max){return s.replace(/<.*?>/ig, '').split(/\s+/).slice(0,max-1).join(' ')}

function getSummaryLikeWP(id) {
        return document.getElementById(id).innerHTML.split(/<!--\s*more\s*-->/)[0];
}

function getSummaryImproved(post,max){
   var re = /<.*?>/gi
   var re2 = /<br.*?>/gi
   var re3 = /(<\/{1}p>)|(<\/{1}div>)/gi
   var re4 = /(<style.*?\/{1}style>)|(<script.*?\/{1}script>)|(<table.*?\/{1}table>)|(<form.*?\/{1}form>)|(<code.*?\/{1}code>)|(<pre.*?\/{1}pre>)/gi
 
   post = post.replace(re4,'')
   post = post.replace(re3,'<br /> ').split(re2)
 
   for(var i=0; i<post.length; i++){
    post[i] = post[i].replace(re,'');
   }
 var post2 = new Array();
 for(var i in post) {
  //if(post[i]!='' && post[i]!=' ' && post[i] != '\n') post2.push(post[i]);
  if(/[a-zA-Z0-9]/.test(post[i])) post2.push(post[i]) ;
 }

  var s = "";
 var indentBlank = "";
 for(var i=0;i<indent;i++){
  indentBlank += " ";
 }
 if(post2.join('<br/>').split(' ').length < max-1 ){
   s = post2.join(indentBlank +' <br/>');
 } else {
  var i = 0;
  while(s.split(' ').length < max){
   s += indentBlank + ' ' + post2[i]+'<br/>';
   i++;
  }
 }
 return s;
}

function createSummaryAndThumb(pID){
 var div = document.getElementById(pID);
 var content = div.innerHTML;
 if (/<!--\s*more\s*-->/.test(content)) {
  div.innerHTML = getSummaryLikeWP(pID);
  div.style.display = "block";
 }
 else {

 var imgtag = "";
 var img = div.getElementsByTagName("img");
 var summ = summary_noimg;
 if(img.length>=1) {
  if(thumbnail_mode == "float") {
   imgtag = '<span class="thumbnailimg"><img src="'+img[0].src+'" /></span>';
   summ = summary_img;
  } else {
   imgtag = '<div class="thumbnailimg" align="center"><img src="'+img[0].src+'" /></div>';
   summ = summary_img;
  }
 }

 var summary = (classicMode) ? imgtag + '<div>' + stripHtmlTags(content,summ) + '</div>' : imgtag + '<div>' + getSummaryImproved(content,summ) + '</div>';

 div.innerHTML = summary;
 div.style.display = "block";
 }
}
//]]>
</script>
<!-- Fim JavaScript Posts Resumidos-->


CÓDIGO CSS
(colar acima de  ]]></b:skin>)

/* BOTÃO LEIA MAIS */
#showlink {
font-size: 13px; /* escolha o tamanho da fonte para o botão */
font-family: 'Montserrat'; /* tipo de letra para o botão */
float: right; /* escolha se quer link flutuando à esquerda ou direita */
margin-right: 20em; /* aplique margens para posicionar link */
margin-bottom: 2em;
margin-top:2.8em; /*a margem negativa para o topo aproxima o link do texto do post */
}
#showlink a {
background: #9587b8;
color:#ffffff;
text-shadow: 1px 1px 0 rgba(0,0,0,0.1);
position:relative;
display:inline-block;
text-align:center;
letter-spacing:1px;
padding: 20px;
padding-top: 8px;
padding-bottom: 8px;
text-decoration: none !important;
}
#showlink a:hover {
color: #fff;
text-decoration: none;
background: #000000;
}

CÓDIGO HTML
(colar em substituição a <div class='post-body entry-content' expr:id='&quot;post-body-&quot; + data:post.id' conforme tutorial)

<!-- Html Resumo Automático de Postagens-->
<div class='post-body entry-content'> 
<b:if cond='data:blog.pageType != &quot;item&quot;'> 
<b:if cond='data:blog.pageType != &quot;static_page&quot;'> 
<div expr:id='&quot;summary&quot; + data:post.id'><data:post.body/></div> 
<script type='text/javascript'>createSummaryAndThumb(&quot;summary<data:post.id/>&quot;);</script> 
<span id='showlink'><a expr:href='data:post.url'>Quero ler o post completo</a></span> 
</b:if></b:if> 
<b:if cond='data:blog.pageType == &quot;item&quot;'> 
<data:post.body/><b:if cond='data:blog.pageType == &quot;item&quot;'/></b:if> 
<b:if cond='data:blog.pageType == &quot;static_page&quot;'><data:post.body/> 
</b:if> 
<div style='clear: both;'/> <!-- clear for photos floats --> 
</div> 
<!-- Fim Html Resumo Automático de Postagens-->


DICA EXTRA- OCULTAR RODAPÉ DOS POSTS NA HOME DO BLOG

Para ocultar post-footer na página inicial do blog cole:

<b:if cond='data:blog.pageType == &quot;item&quot;'>

acima de:

<div class='post-footer'>

e feche a condicional colando:

</b:if>

acima de

</b:includable>


Home Sobre mim Tutoriais Loja de templates Portfólio Fanpage