¿Estás enterado de todos los resultados deportivos? En Altas Pulsaciones te ponemos al día


18 Dic

Mostrar titulo de todas o ultimas entradas

Desde nuestro blog amigo La Blogueria Les traeos un exelente widget para que puedan agregar a su blog. Se trata de mostrar todas o las ultimas entradas en tu blog, para asi insitar al lector que siga navegando por nuestro blog.

Como veran yo ya lo he aplicado y me parece exelente. Pueden verlo entrando al link de esta entrada, debajo de todo, luego de los comentarios, alli apareceran las ultimas entradas de “Recursos Blog” ustedes pueden hacerlo mismo en su blog. Solo sigue estos pasos…

1- Entra tu platilla html, expande los artilugios y busca con CTRL + F, </head> y añade el siguiente codigo antes del head.

<script type=’text/javascript’>
// Developed by Hoctro - All rights reserved 2007
// This credit must be included in all your derived usages.

// “cb” is intended to be a common library, where different widgets would
// utitlize the shared operations such as getTitle, getLink, etc. from a json object.
var cb = {

// search function requires these parameters:
// 1. query: a blogger address, such as “hoctro.blogspot.com”,
// 2. type: type of return data, either “comments” or “posts”,
// 3. start: the start-index parameter (where to start extracting data)
// 4. increment: the number of elements the json will get back. (the smaller value, the faster time to travel back)
// 5. func: the returned function the json object will feed.

search: function(query, type, start, increment, func) {
var script = document.createElement(’script’);
script.setAttribute(’src’, ‘http://’ + query + ‘/feeds/’ + type + ‘/default?alt=json-in-script&amp;start-index=’
+ start + ‘&amp;max-results=’ + increment + ‘&amp;callback=’ + func + ‘&amp;orderby=published’);
script.setAttribute(’type’, ‘text/javascript’);
document.documentElement.firstChild.appendChild(script);
},

// searchLabel function return a result of posts w/ a label query
// it requires these parameters:
// 1. query: a blogger address, such as “hoctro.blogspot.com”,
// 2. an array of labels
// 3. func: the returned function the json object will feed.
searchLabel: function(query, label, func) {
var script = document.createElement(’script’);
script.setAttribute(’src’, ‘http://’ + query + ‘/feeds/posts/default/-/’ + encodeURIComponent(label) +
‘?alt=json-in-script&amp;callback=’ + func + ‘&amp;orderby=published’);
script.setAttribute(’type’, ‘text/javascript’);
document.documentElement.firstChild.appendChild(script);
},

// getTotalResults needs the json object, and it’ll return the total number of comments (or posts) of the blog.
getTotalResults: function(json) {
return json.feed.openSearch$totalResults.$t;
},

// getStartIndex gets the start index of a search inside an json object.
getStartIndex: function(json) {
return json.feed.openSearch$startIndex.$t;
},

// getLink return a href link if “name” matches the content inside “a” tags) of the link
getLink: function(entry, name) {
var alturl;

for (var k = 0; k &lt; entry.link.length; k++) {
if (entry.link[k].rel == name)
alturl = entry.link[k].href;
}
return alturl;
},

// getTitle gets the title of the title of an entry of a json object.
getTitle: function(entry) {
return entry.title.$t;
},

// getContent gets the content inside an entry of a json object.
getContent: function(entry) {
return entry.content.$t;
},

// getCommentAuthor: gets the commenter name inside an entry of a json object.
getCommentAuthor: function(entry) {
return entry.author[0].name.$t;
},

// Given a json label search, this function return the decoded label.
getLabelFromURL: function(json) {
for (var l = 0; l &lt; json.feed.link.length; l++) {
if (json.feed.link[l].rel == ‘alternate’) {
var raw = json.feed.link[l].href;
// The next two lines are borrowed from Ramani’s Neo Template
// code. Thanks Ramani!
var label = raw.substr(raw.lastIndexOf(’/')+1);
return decodeURIComponent(label);
}
}
},
txt : function (s) {
return s + ” Widget by &lt;a href=’http://hoctro.blogspot.com” + “‘&gt;Hoctro&lt;/a&gt;”;
}
};
</script>

2- Busca cualquier etiqueta </b:widget> y añade despues lo siguiente

<b:widget id=’HTML101′ locked=’false’ title=’TODAS LAS ENTRADAS’ type=’HTML’>
<b:includable id=’main’>
<!– only display title if it’s non-empty –>
<b:if cond=’data:title != “”‘>
<h2 class=’title’><data:title/></h2>
</b:if>
<div class=’widget-content’>
<data:content/>
<ul><div id=’dataPost’/></ul>
<h6 id=’hoctro’>Post Widget by <a href=’http://hoctro.blogspot.com’>Hoctro</a></h6>
</div>

<script type=’text/javascript’>
// Developed by Hoctro - All rights reserved 2007
// This credit must be included in all your derived usages.
// This widget lists the available posts based on the uP.nPost value below
// Use -1 if you want them all.
var uP = {
nPost : -1
};

var cP = {
// private variable to store the total results
totCount : 0,
// the number of elements for each json call
increment : 10,
// this is the place to define the blog name for subsequent retrieval data
web : “TUBLOG.blogspot.com”,

listPosts: function(json, tag) {

var text=”";

for (var i = 0; i &lt; json.feed.entry.length; i++) {
var entry = json.feed.entry[i];

text += “<li>” + “&lt;a href=’” + cb.getLink(entry, “alternate”)
+ “‘&gt;” + cb.getTitle(entry) + “</li>”;
}
var p = document.createElement(’span’);
document.getElementById(tag).appendChild(p);
p.innerHTML = text;
},

callPostJson: function(json) {
this.listPosts(json, “dataPost”);
},

getCo : function(json) {
this.totCount = cb.getTotalResults(json);
var count = (uP.nPost &lt; 0) ? this.totCount : uP.nPost;
var i=1;
while(i&lt;=count) {
var incr = (count-i &lt; this.increment) ? count-i+1 : this.increment;
cb.search( cP.web, “posts”, i, incr, ‘cP.callPostJson’);
if (incr==0) incr=incr+1;
i = i+incr;
}
}
};

cb.search( cP.web, “posts”, 1, 2, ‘cP.getCo’);

</script>
</b:includable>
</b:widget>

Cambia la URL por la de tu blog; el valor resaltado -1 indica mostra infinito post. Lo puedes cambiar la cantidad que mas te guste. Yo estoy usando con 20 ultimos post

  • Enviar a:
  • Fresqui
  • Meneame
  • Barrapunto
  • MisterWong
  • Del.icio.us
  • co.mments
  • Yahoo
trackback Dirección Trackback
categorias Categoría/s: Javascript, Trucos
tags Tags: No Tags

Publicidad

1 comentario en “Mostrar titulo de todas o ultimas entradas”

  1. Jezabell
    1

    Hola, me gustaria saber si se puede adaptar esto a la plantilla antigua, la clásica. A ver si puedes decirme dónde tendría que ubicar los códigos.
    Gracias desde ya!
    Saludos
    Jezabell

Deja un comentario

Agradeceríamos conocer tu opinión acerca de esta entrada. Abstente de insultar y de utilizar palabras malsonantes. Aquellos comentarios o nicks que no se ajusten a lo anterior, o que mencionen o enlacen a otras webs de forma promocional y descontextualizada, serán borrados/modificados inmediatamente.

Puedes usar las siguientes etiquetas: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Publicidad