Bài Viết Ngẫu Nhiên Cho Blogspot

Bài liên quan

[Widget] Bài Viết Ngẫu Nhiên Cho Blogspot

Trong việc thiết kế blogspot thì cần rất nhiều thời gian, làm những việc quan trọng, trong đó việc tạo bài viết ngẫu nhiên cũng rất quan trong. Vì vậ, Anh Nhím Blog sẽ hướng dẫn các bạn tạo bài đăng ngẫu nhiên cho blog

Mục lục:

  • Mục Đích
  • Thực Hiện
  • Lời Kết

Mục Đích

  • Giúp người dùng có cơ hội đọc được các bài cũ 
  • Làm đa dạng, phong phú hơn về hiển thị bài viết.
  • .....

Thực Hiện

1. Các bạn đăng nhập Blogger >> Bố cục >> Thêm tiện ích >> HTML/Javascript
Các bạn nên thêm tiện ích này ở sidebar thì nó sẽ đẹp hơn, có tính khoa học hơn
[Widget] Bài Viết Ngẫu Nhiên Cho Blogspot


2. Sau đó các bạn chép code bên dưới vào trong khung HTML/Javasript đó
<style scoped='' type="text/css">
#anhim-randompost ul{list-style:none;margin:0;padding:0}#anhim-randompost li{display:block;clear:both;overflow:hidden;list-style:none;border-bottom:1px solid #e3e3e3;word-break:break-word;padding:10px 0;margin:0;}
#anhim-randompost li:last-child{border-bottom:0;}
#anhim-randompost li a{color:#444;}#anhim-randompost li a:hover{color:#444;text-decoration:underline}
</style>
<div id='anhim-randompost'>Loading...</div>
<script>
//<![CDATA[
// Random Post Widget
var homePage = 'http://www.anhnhim.net',
    maxResults = 10,
    containerId = 'anhim-randompost';
function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
function shuffleArray(arr) {
    var i = arr.length, j, temp;
    if (i === 0) return false;
    while (--i) {
        j = Math.floor(Math.random() * (i + 1));
        temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
    return arr;
}
function ArlinaRandomPosts(json) {
    var startIndex = getRandomInt(1, (json.feed.openSearch$totalResults.$t - maxResults));
    // console.log('Get the post feed start from ' + startIndex + ' until ' + (startIndex + maxResults));
    document.write('<scr' + 'ipt src="' + homePage + '/feeds/posts/summary?alt=json-in-script&orderby=updated&start-index=' + startIndex + '&max-results=' + maxResults + '&callback=randomPosts"></scr' + 'ipt>');
}
function randomPosts(json) {
    var link, ct = document.getElementById(containerId),
        entry = shuffleArray(json.feed.entry),
        skeleton = "<ul>";
    for (var i = 0, len = entry.length; i < len; i++) {
        for (var j = 0, jen = entry[i].link.length; j < jen; j++) {
            link = (entry[i].link[j].rel == "alternate") ? entry[i].link[j].href : '#';
        }
        skeleton += '<li><a href="' + link + '">' + entry[i].title.$t + '</a></li>';
    }
    ct.innerHTML = skeleton + '</ul>';
}
document.write('<scr' + 'ipt src="' + homePage + '/feeds/posts/summary?alt=json-in-script&max-results=0&callback=ArlinaRandomPosts"></scr' + 'ipt>');
//]]>
</script>
Các bạn nhớ thay đổi link màu xanh dương http://www.anhnhim.net thành URL blog của bạn và thay số 10 thành số bài viết bạn muốn hiện thị.
3. Nhấn Lưu >> Lưu sắp xếp
Demo
click to view

Lời Kết

Vậy là mình đã hướng dẫn các bạn , nếu có thắc mắc các bạn cứ comment bên dưới hoặc liên hệ mình, mình sẽ giải đáp. Chúc các bạn thành công

Đam mê công nghệ, lập trình web, game đua xe và nhiều thứ khác. Thích học hỏi, tìm tòi nhiều kiến thức hay bổ ích. Thích chia sẽ cho mọi người, bạn bè về những kiến thức học được.

Bài Viết Liên Quan

Previous
Next Post »

Biểu tượng mặt cười ( Copy & paste xuống phần Comment )
Hãy Luôn Comment Để Tạo Động Lực Cho Tác Giả

Emoticon

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
-_-
(o)
[-(
:-?
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
$-)
(y)
(f)
x-)
(k)
(h)
(c)
cheer
(li)
(pl)