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&start-index=’
+ start + ‘&max-results=’ + increment + ‘&callback=’ + func + ‘&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&callback=’ + func + ‘&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 < 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 < 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 <a href=’http://hoctro.blogspot.com” + “‘>Hoctro</a>”;
}
};
</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 < json.feed.entry.length; i++) {
var entry = json.feed.entry[i];
text += “<li>” + “<a href=’” + cb.getLink(entry, “alternate”)
+ “‘>” + 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 < 0) ? this.totCount : uP.nPost;
var i=1;
while(i<=count) {
var incr = (count-i < 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










Categoría/s:
Tags: No Tags
19/12/2007 - 14:17
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