Breaking

Wednesday, May 29, 2013

Blogspot Statistic - Cải tiến tiện ích Thống kê mặc định của blog (totalPosts, totalComment, totalCount)

Hiển thị thống kê tổng số bài đăng, tổng bình luận, tổng lượt xem khá đơn giản. Nên bạn có thể tự làm css để hình thức thêm sinh động


Bước 1: Bố cục -> Thêm tiện ích mở rộng "Thống kê blog" -> Chỉ chọn số cho đơn giản.

Bước 2
Mẫu -> Chỉnh sửa HTML -> Chuyển đến tiện ích Stats1
Code bạn đầu của nó là:
<b:widget id='Stats1' locked='false' title='Tổng số lượt xem trang' type='Stats'>
        <b:includable id='main'>
                <b:if cond='data:title'>
                        <h2><data:title/></h2>
                </b:if>
                <div class='widget-content'>
                        <!-- Content is going to be visible when data will be fetched from server. -->
                        <div expr:id='data:widget.instanceId + &quot;_content&quot;' style='display: none;'>
                                <!-- Counter and image will be injected later via AJAX call. -->
                                <b:if cond='data:showSparkline'>
                                        <img alt='Sparkline' expr:id='data:widget.instanceId + &quot;_sparkline&quot;' height='30' width='75' />
                                </b:if>
                                <b:if cond='data:showGraphicalCounter'><span class='counter-wrapper graph-counter-wrapper' expr:id='data:widget.instanceId + &quot;_totalCount&quot;' /><b:else/><span class='counter-wrapper text-counter-wrapper' expr:id='data:widget.instanceId + &quot;_totalCount&quot;' />
                                </b:if><b:include name='quickedit' />
                        </div>
                </div>
        </b:includable>
</b:widget>
Ta thay thế nó bằng một trong các đoạn code sau:
<b:widget id='Stats1' locked='false' title='' type='Stats'>
        <b:includable id='main'>
                <div class='widget-content'>
                        <ul>
                                <li>Tổng số bài đăng :<span id='Stats1_totalPosts' />
                                </li>
                                <li>Tổng số bình luận :<span id='Stats1_totalComments' />
                                </li>
                                <li>Tổng lượt xem trang :<span expr:id='data:widget.instanceId + &quot;_totalCount&quot;' />
                                </li>
                        </ul>
                        <script type='text/javascript'>
                                //<![CDATA[
                                function totalPosts(json) {
                                        document.getElementById('Stats1_totalPosts')
                                                .innerHTML = json.feed.openSearch$totalResults.$t
                                };
                                function totalComments(json) {
                                        document.getElementById('Stats1_totalComments')
                                                .innerHTML = json.feed.openSearch$totalResults.$t
                                };
                                document.write(
                                        '<script type=\"text/javascript\" src=\"/feeds/posts/default?alt=json-in-script&max-results=0&callback=totalPosts\"><\/script><script type=\"text/javascript\" src=\"/feeds/comments/default?alt=json-in-script&max-results=0&callback=totalComments\"><\/script>');
                                 //]]>
                        </script>
                </div>
        </b:includable>
</b:widget>
Hoặc:
<b:widget id='Stats1' locked='false' title='' type='Stats'>
        <b:includable id='main'>
                <div class='widget-content'>
                        <ul>
                                <li>Tổng số bài đăng :<span id='Stats1_totalPosts' />
                                </li>
                                <li>Tổng số bình luận :<span id='Stats1_totalComments' />
                                </li>
                                <li>Tổng lượt xem trang :<span id='Stats1_totalCount' />
                                </li>
                        </ul>
                        <script type='text/javascript'>
                                //<![CDATA[
                                function totalPosts(json) {
                                        document.getElementById('Stats1_totalPosts')
                                                .innerHTML = json.feed.openSearch$totalResults.$t
                                };
                                function totalComments(json) {
                                        document.getElementById('Stats1_totalComments')
                                                .innerHTML = json.feed.openSearch$totalResults.$t
                                };
                                document.write(
                                        '<script type=\"text/javascript\" src=\"/feeds/posts/default?alt=json-in-script&max-results=0&callback=totalPosts\"><\/script><script type=\"text/javascript\" src=\"/feeds/comments/default?alt=json-in-script&max-results=0&callback=totalComments\"><\/script>');
                                 //]]>
                        </script>
                </div>
        </b:includable>
</b:widget>
thaoj

No comments:

Post a Comment