[Blogger] code hiện các bài label ra page

  • blogger
    Demo:

    Mô tả: code cho vào page của blogger. thực hiện chức năng như 1 chuyên mục. như này mình vẫn seo page bình thường và chức năng thì tương tự như label ( nhưng nó tối ưu hơn về mô tả và url) url đẹp hơn và chuyên nghiệp hơn . như ở demo thì url domain/p/url đẹp hơn là domain/seach/label/url

    Code:
    <div class='post-view'>
    <h1>Tìm Hiểu Về Bệnh Bao Quy Đầu</h1>
    <div style='clear: both;'></div>
    <style>
    #hotrofmnet {
      font:normal 11px/14px Arial,Sans-Serif;
      color:#666;
      text-align:justify;
      margin:0px auto;
    }

    #loadingscript {
      background:#F6EFBB url('http://reader-download.googlecode.com/files/ajax-loader.gif') no-repeat 50% 46%;
      padding:10px;
      font:bold 20px Georgia,Serif;
      color:black;
      height:400px;
      text-indent:-9999px;
      -webkit-box-shadow:inset 0px 0px 0px 5px #EAE0AD;
      -moz-box-shadow:inset 0px 0px 0px 5px #EAE0AD;
      box-shadow:inset 0px 0px 0px 5px #EAE0AD;
    }

    .itempost-hotrofms {
      margin:0px auto 5px;
      height:auto;
      overflow:hidden;
      display:block;
    }

    .itempost-hotrofms h2 {
    margin: 0px auto 6px;
    font: bold 130% Geneva,sans-serif;
    text-transform: none;
    float: left;
    width: 100%;
    }
    .summary{
    font-size:13px;
    }
    .itempost-hotrofms h2 a {
      color:black;
      text-decoration:none;
    }

    .itempost-hotrofms h2 a:hover {
      color:#CF152A;
      text-decoration:none;
    }

    .itempost-hotrofms img {
      float:left;
      height:85px;
      width:124px;
      margin:2px 10px 2px 0px;
      -webkit-box-shadow:none;
      -moz-box-shadow:none;
      box-shadow:none;
      background-color:#fafafa;
      border:1px solid #dcdcdc;
      padding:4px;
    }

    .itempost-hotrofms .iteminside {
      padding:10px;
      background-color:#f2f2f2;
      background-image:-webkit-linear-gradient(top, #f2f2f2, white);
      background-image:-moz-linear-gradient(top, #f2f2f2, white);
      background-image:-ms-linear-gradient(top, #f2f2f2, white);
      background-image:-o-linear-gradient(top, #f2f2f2, white);
      background-image:linear-gradient(top, #f2f2f2, white);
      border-top:1px solid #e5e5e5;
      -webkit-box-shadow:inset 0px 1px 0px white;
      -moz-box-shadow:inset 0px 1px 0px white;
      box-shadow:inset 0px 1px 0px white;
    }

    .itempost-hotrofms .itemfoot {
      clear:both;
      border:1px solid #EAE7DB;
      padding:5px 10px;
      margin:10px 0px 0px;
      background-color:#FAFAE7;
      color:#4B86C1;
      overflow:hidden;
    }

    .itempost-hotrofms .itemfoot a.itemrmore {
      font-weight:bold;
      color:#895F30;
      float:right;
      text-decoration:none;
    }

    .itempost-hotrofms .itemfoot a.itemrmore:hover {
      color:#9BB009;
      text-decoration:underline;
    }

    #itempager {
      background-color:#F2F0F1;
      padding:10px 0px;
      border-top:1px solid #E5E5E5;
      -webkit-box-shadow:inset 0px 1px 0px white;
      -moz-box-shadow:inset 0px 1px 0px white;
      box-shadow:inset 0px 1px 0px white;
    }

    #pagination, #totalposts {
      color:#999;
      font:bold 10px Verdana,Arial,Sans-Serif;
      padding:0px;
      margin-bottom:10px;
      text-align:center;
    }

    #pagination span, #pagination a {
      border:1px solid #e5e5e5;
      color:white;
      display:inline;
      margin:0 1px;
      padding:2px 5px;
      text-indent:0px;
      background-color:#8899D0;
      text-decoration:none;
    }
     
    #pagination span.actual,
    #pagination a:hover {
      background-color:#7483BC;
    }

    #pagination span.hidden {
      display:none;
    }
    </style>
    <script type="text/javascript">
    var showPostDate = true,
    showComments = false,
    idMode = true,
    sortByLabel = true,//Theo nhãn thì để chế độ:true
    labelSorter = "dien-label",
    loadingText = "Loading...",
    totalPostLabel = "Tổng số bài viết:",
    jumpPageLabel = "Trang",
    commentsLabel = "Comment",
    rmoreText = "Đọc tiếp ►",
    prevText = "Prew",
    nextText = "Next",
    siteUrl = "http://www.domain.com/",//URL Blog
    postsperpage = 10,//Số bài trong 1 trang
    numchars = 250,
    imgBlank = "http://2.bp.blogspot.com/-11FkySHGB5Y/TpZ6SSbsF2I/AAAAAAAAA94/zK10UaL7jgo/s1600/images.jpeg";//Ảnh đại diện khi bài không có ảnh
    </script>
    <script type="text/javascript">
    // -----------------------------------------------------------------------------------------
    // Table of Content for Blogger with Pagination
    // -----------------------------------------------------------------------------------------

    var minpage = 6; // Minimum number to display the page
    var maxpage = 10; // The maximum number of pages to display
    var firstpage = 0; // Detect the first time it is executed
    var pagernum = 0; // Contain the page number where we
    var postsnum = 0; // Start the first page
    var actualpage = 1; // Starting value of the current page (it will change if you click the pagination).

    // This is the container template that will be used to insert post template, pagination and the posts count
    document.write('<div id="hotrofmnet"><div id="results"></div><div id="itempager" style="position:relative;"><div id="pagination"></div><div id="totalposts"></div></div></div>');

    var _results = document.getElementById('results');
    var _pagination = document.getElementById('pagination');
    var _totalposts = document.getElementById('totalposts');

    // Build the table of contents framework

    function showPagePosts(json) {

        var entry, posttitle, posturl, postimg, postsumm, replies, monthnames, timepub, output = "";

        if (pagernum == 0) {
            postsnum = parseInt(json.feed.openSearch$totalResults.$t);
            pagernum = parseInt(postsnum / postsperpage) + 1;
        }

        for (var i = 0; i < postsperpage; i++) {

            if (i == json.feed.entry.length) break;

            entry = json.feed.entry[i];
            posttitle = entry.title.$t; // Get the post title

            // Get rel="alternate" for truly post url
            for (var k = 0, elen = entry.link.length; k < elen; k++) {
                if (entry.link[k].rel == 'alternate') {
                    posturl = entry.link[k].href; // This is your real post URL!
                    break;
                }
            }

            // Get the comments count
            for (var l = 0, clen = entry.link.length; l < clen; l++) {
                if (entry.link[l].rel == "replies" && entry.link[l].type == "text/html") {
                    var commentsnum = entry.link[l].title.split(" ")[0]; // This is your comments count
                    break;
                }
            }

            // If the Blogger-feed is set to SHORT, then the content is in the summary-field
            postsumm = ("summary" in entry) ? entry.summary.$t.replace(/<br ?\/?>/ig, " ").replace(/<(.*?)>/g, "") : ""; // Get the post summary

            // Reduce post summaries to "numchars" characters.
            // "numchars" is a variable. You determine the value
            if (postsumm.length > numchars) {
                postsumm = (numchars > 0 && numchars !== false) ? postsumm.substring(0, numchars) + '...' : "";
            }

            // Get the post date (e.g: 2012-02-07T12:56:00.000+07:00)
            var _postdate = entry.published.$t,
                _cdyear = _postdate.substring(0, 4), // Take 4 characters from the "postdate" beginning, it means the year (2012)
                _cdmonth = _postdate.substring(5, 7), // Take 2 character 5 step from "postdate" beginning, it mean the month (02)
                _cdday = _postdate.substring(8, 10); // Take 2 character 8 step from "postdate" beginning. it means the day (07)

            // Month array template
            monthnames = (idMode) ? ["1", " 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9", " 10", " 11", " 12"] : [" 1", " 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9", " 10", " 11", " 12"];

            // The final product of the post date = (07 Feb 2012) (cdday monthnames cdyear)
            timepub = (showPostDate) ? _cdday + ' / ' + monthnames[parseInt(_cdmonth, 10) - 1] + ' / ' + _cdyear + '  ' : '';

            // The final product of the comments count & comments label (10 Komentar) (commentsnum commentsLabel)
            replies = (showComments) ? commentsnum + ' ' + commentsLabel : '';

            // Get the post thumbnails
            postimg = ("media$thumbnail" in entry) ? entry.media$thumbnail.url : imgBlank;

            // Build the post template
            output += '<div class="itempost-hotrofms">';
            output += '<h2><a href="' + posturl + '" >' + posttitle + '</a></h2><br/><a href="' + posturl + '" ><img src="' + postimg + '" /></a><span class="summary">' + postsumm + '</span><div class="itemfoot">' + timepub + replies + '<a class="itemrmore" href="' + posturl + '" >' + rmoreText + '</a></div></div>';
            output += '<div class="iteminside">';
            output += '<div style="padding: 3px;border-bottom: 1px dotted #d1d1d1;"></div>';
            output += '</div>';

        }

        // Put the whole template above into <div id="results"></div>
        _results.innerHTML = output;
        _create_pagination();

    }

    // Build the pagination
    function _create_pagination() {

        output = "";
        var starter = 0;

        output += (actualpage > 1) ? '<a title="' + prevText + '" class="prevjson" href="javascript:_init_script(' + parseInt(actualpage - 1) + ')">' + prevText + '</a>' : '<span class="prevjson hidden">' + prevText + '</span>';

        if (pagernum < (maxpage + 1)) {
            for (starter = 1; starter <= pagernum; starter++) {
                output += (starter == actualpage) ? '<span class="actual">' + starter + '</span>' : '<a href="javascript:_init_script(' + starter + ')">' + starter + '</a>';
            }
        } else if (pagernum > (maxpage - 1)) {
            if (actualpage < minpage) {
                for (starter = 1; starter < (maxpage - 2); starter++) {
                    output += (starter == actualpage) ? '<span class="actual">' + starter + '</span>' : '<a href="javascript:_init_script(' + starter + ')">' + starter + '</a>';
                }
                output += ' ... ';
                output += '<a href="javascript:_init_script(' + parseInt(pagernum - 1) + ')">' + parseInt(pagernum - 1) + '</a>';
                output += '<a href="javascript:_init_script(' + pagernum + ')">' + pagernum + '</a>';
            } else if (pagernum - (minpage - 1) > actualpage && actualpage > (minpage - 1)) {
                output += '<a href="javascript:_init_script(1)">1</a>';
                output += '<a href="javascript:_init_script(2)">2</a>';
                output += ' ... ';
                for (starter = actualpage - 2; starter <= actualpage + 2; starter++) {
                    output += (starter == actualpage) ? '<span class="actual">' + starter + '</span>' : '<a href="javascript:_init_script(' + starter + ')">' + starter + '</a>';
                }
                output += ' ... ';
                output += '<a href="javascript:_init_script(' + parseInt(pagernum - 1) + ')">' + parseInt(pagernum - 1) + '</a>';
                output += '<a href="javascript:_init_script(' + pagernum + ')">' + pagernum + '</a>';
            } else {
                output += '<a href="javascript:_init_script(1)">1</a>';
                output += '<a href="javascript:_init_script(2)">2</a>';
                output += ' ... ';
                for (starter = pagernum - (minpage + 1); starter <= pagernum; starter++) {
                    output += (starter == actualpage) ? '<span class="actual">' + starter + '</span>' : '<a href="javascript:_init_script(' + starter + ')">' + starter + '</a>';
                }
            }
        }

        output += (actualpage < starter - 1) ? '<a title="' + nextText + '" class="nextjson" href="javascript:_init_script(' + parseInt(actualpage + 1) + ')">' + nextText + '</a>' : '<span class="nextjson hidden">' + nextText + '</span>';

        _pagination.innerHTML = output;
        var parameter = (actualpage * postsperpage) - (postsperpage - 1),
            _final = actualpage * postsperpage;
        _totalposts.innerHTML = totalPostLabel + ' ' + postsnum + ' - ' + jumpPageLabel + ' ' + parameter + ' - ' + _final;
    }

    // Functions to remove and append the callback script that has been manipulated in the `start-index` parameter
    function _init_script(n) {

        var parameter = (n * postsperpage) - (postsperpage - 1);
        var url = (sortByLabel) ? siteUrl + '/feeds/posts/summary/-/' + labelSorter + '?start-index=' + parameter : siteUrl + '/feeds/posts/summary/?start-index=' + parameter; // Optional: Sort posts by a specific label

        if (firstpage == 1) {
            var old = document.getElementById("TEMPORAL");
            old.parentNode.removeChild(old);
        }
        _results.innerHTML = '<div id="loadingscript">' + loadingText + '</div>';
        _pagination.innerHTML = '';
        _totalposts.innerHTML = '';

        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = url + '&max-results=' + postsperpage + '&orderby=published&alt=json-in-script&callback=showPagePosts';
        script.id = 'TEMPORAL';
        document.getElementsByTagName('head')[0].appendChild(script);
        firstpage = 1;
        actualpage = n;
    }

    // Execute the _init_script() function with parameter as `1` on page load
    // So it will show the first page.
    window.onload = function () {
        _init_script(1);
    };
    </script>


    Các bạn tìm 2 dòng sau và sửa lại cho đúng website của mình nhé

    labelSorter = "dien-label",

    siteUrl = "http://www.domain.com/",//URL Blog

Thông tin tác giả
avatar
MEM LV2
Bài viết :
88
Points :
236
Like :
36
blogger
An toàn
Xem lý lịch thành viên
Bài viết liên quan
    Đang tải dữ liệu

Permissions in this forum:
Bạn không có quyền trả lời bài viết