Vibay
Hiển thị các bài đăng có nhãn Blogger Code. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Blogger Code. Hiển thị tất cả bài đăng

Chủ Nhật, 21 tháng 7, 2019

Nhúng Video từ OK.ru vào blogger/ blogspot

Vì một lý do nào đó OK.ru không cho phép bạn nhúng video vào blogspot, bạn vẫn có thể làm việc này bằng cách tạo mã Video Widget bằng code sau:

<div id="ok_content_widget" style="border: 0; padding: 0; margin: 0 auto; max-width: 100%;"></div>
<script>
!function (d, id, did, st) {
var js = d.createElement("script");
js.src = "https://connect.ok.ru/connect.js";
js.onload = js.onreadystatechange = function () {
if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") {
if (!this.executed) {
this.executed = true;
setTimeout(function () {
OK.CONNECT.insertContentWidget(id,did,st);
}, 0);
}
}};
d.documentElement.appendChild(js);
}(document,"ok_content_widget","OK.ru_video_link",'{"topicTextIsFull":1}');
</script>

Trong đó: OK.ru_video_link là link video của OK.ru, ví dụ: https://ok.ru/video/1285035985478

Bạn cũng có thể vào liên kết này để tạo Video Widget cho video của OK.ru : https://apiok.ru/en/ext/content

Tệp JS OK.ru connect: https://drive.google.com/file/d/1WBL-Nssi9MqrOWRuagwOZVciUtybY1k3/view?usp=sharing

0

Thứ Bảy, 20 tháng 7, 2019

Bài Viết Liên Quan Trên Sidebar (Related post Sidebar) cho Blogspot

Tiện Ích Bài Viết Liên Quan Mới Nhất Cho Nhãn Trên Sidebar


Bài Viết Liên Quan (Related post) là một phần rất quan trọng trong việc điều hướng cũng như cung cấp nội dung cần thiết tới người đọc khi họ đang quan tâm một bài biết của bạn. Các bài viết thủ thuật blogspot về Bài Viết Liên Quan đã được chia sẻ khá nhiều nhưng bài viết liên quan nằm trên Sidebar left (hoặc right) thì lại khá hiếm hoi. Hôm nay, tôi có góp nhặt được thủ thuật này, xin chia sẻ cùng bạn đọc.

Demo: Giống sidebar của blog này.

Cách thực hiện:

Bước 1. Đăng nhập Blogger, vào Bố cục>> Thêm tiện ích >> Thêm 1 HTML/Javascript


Đặt tên cho tiện ích (Bài viết liên quan), dán vào phần nội dung tiện ích bằng đoạn code sau đây (Lưu ý mình đã chú ý script để các bạn có thể hiểu tường tận hơn, có thể tùy biến CSS theo ý thích của bạn). (Thay các thông số cho phù hợp với blog của bạn)


<script type="text/javascript">
// Recent and Related Posts for Label on Sidebar
var post_per_page = 5; // thiết lập số bài viết hiển thị mỗi trang
var post_snippet = 70; // thiết lập số ký tự tóm tắt bài viết
var homepage = "http://chiase-thuthuat.blogspot.com"; // đặt địa chỉ trang chủ của bạn
var img_default = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOTOJ8hxa12MTcGpZ31eYJywlj7rRiZ7nZ_Dn-_BBhYz_Y3OnelJAgwFX0wJ-gRFcTaARRl3NAfMwRcbw4DmbWwJ5j8qr37Aowm0lsUmVkV9wgjkX_MPYfBaPht5y4OiBthyphenhyphendNj-5-KHg/s1600/recentpostnothumb.png"; // thiết lập URL hình mặc định
var pr_flagfirst = 0;
var url_prev, url_next;
// chức năng tạo tóm tắt bài viết
function removeHtmlTag(strx,chop){
var summary = strx.split("<");
for(var i=0;i<summary.length;i++){
if(summary[i].indexOf(">")!=-1){
summary[i] = summary[i].substring(summary[i].indexOf(">")+1,summary[i].length);
}
}
summary = summary.join("");
summary = summary.substring(0,chop-1);
return summary;
}
// chức năng tạo biến
function showpagelabel(json) {
var entry, posttitle, posturl, postimg, postcontent;
var str_out = "";
// tìm URL phân trang
for (var k = 0; k < json.feed.link.length; k++) {
if (json.feed.link[k].rel == 'previous') {
// đây là trang trước
url_prev = json.feed.link[k].href;
}
if (json.feed.link[k].rel == 'next') {
// đây là trang sau
url_next = json.feed.link[k].href;
}
}
// đọc và xác định bài viết
for (var i = 0; i < post_per_page; i++) {
// nếu không có thì kết thúc lệnh
if (i == json.feed.entry.length) { break; }
entry = json.feed.entry[i];
// đây là tiêu đề bài viết
posttitle = entry.title.$t;
// tìm URL bài viết
for (var k = 0; k < entry.link.length; k++) {
if (entry.link[k].rel == 'alternate') {
// lưu trữ nó
posturl = entry.link[k].href;
break;
}
}
// tìm nội dung bài viết và lưu trữ nó
if ("content" in entry) {
postcontent = entry.content.$t;
} else if ("summary" in entry) {
postcontent = entry.summary.$t;
} else {
postcontent = "";
}
// tìm ảnh đại diện hoặc sử dụng ảnh mặc định
if ("media$thumbnail" in entry) {
postimg = entry.media$thumbnail.url;
} else {
postimg = img_default;
}
// kết thúc đọc, tạo code HTML
str_out += "<div class='pagi_label'>";
str_out += "<a href='" + posturl + "' target='_blank'><img src='" + postimg + "' /></a>";
str_out += "<h6>
<a href='" + posturl + "' target='_blank'>" + posttitle + "</a></h6>
";
str_out += "<p>
" + removeHtmlTag(postcontent,post_snippet) + " ...</p>
";
str_out += "</div>
";
}
// kết thúc lệnh và viết kết quả
document.getElementById("Sidebar_Label").innerHTML = str_out;
// tạo phần phân trang
str_out = "";
// nếu có trang trước, tạo link nhưng chỉ có text
if(url_prev) {
str_out += "<a href='javascript:navi_pagi_label(-1);' class='previous'>Prev</a>";
} else {
str_out += "<span class='disabled previous'>Prev</span>";
}
// nếu có trang sau, tạo link nhưng chỉ có text
if(url_next) {
str_out += "<a href='javascript:navi_pagi_label(1);' class='next'>Next</a>";
} else {
str_out += "<span class='disabled next'>Next</span>";
}
// tạo link cho trang đầu
str_out += "<a href='javascript:navi_pagi_label(0);' class='first'>First</a>";
// viết code
document.getElementById("PR_Label_Sidebar").innerHTML = str_out;
}
// chức năng tạo địa chỉ feed sẽ đọc
function navi_pagi_label(direction){
var p, parameters;
if(direction==-1) {
// trang trước
p = url_prev.indexOf("?");
parameters = url_prev.substring(p);
} else if (direction==1) {
// trang sau
p = url_next.indexOf("?");
parameters = url_next.substring(p);
} else {
// trang đầu
parameters = "?start-index=1&max-results=" + post_per_page + "&orderby=published&alt=json-in-script"
}
parameters += "&callback=showpagelabel";
include_script(parameters);
}
// đây là chức năng load script động
function include_script(parameters) {
// nếu không phải lần đầu tiên thì loại script trên
if(pr_flagfirst==1) {remover_script();}
// xóa mọi thứ và đặt một dòng text hoặc ảnh load
document.getElementById("Sidebar_Label").innerHTML = "<div id='loading_script'>
</div>
";
document.getElementById("PR_Label_Sidebar").innerHTML = "";
// đây là lưu trữ feed
var archive_feeds = homepage + "/feeds/posts/default/-/" + label_Related + parameters;
// load và cho chạy
var nouvo = document.createElement('script');
nouvo.setAttribute('type', 'text/javascript');
nouvo.setAttribute('src', archive_feeds);
nouvo.setAttribute('id', 'LABELTEMPORAL');
document.getElementsByTagName('head')[0].appendChild(nouvo);
pr_flagfirst = 1;
}
// đây là chức năng loại bỏ script đã được load trước
function remover_script() {
var that = document.getElementById("LABELTEMPORAL");
var father = that.parentNode;
father.removeChild(that);
}
// khi load trang thì bắt đầu chức năng
onload=function() { navi_pagi_label(0); }
</script>
<style type="text/css">
#Sidebar_Label {margin: 0 auto;width:100%}
.pagi_label {background-color: #ffffff;border-bottom: 1px dashed #101921;height: 72px;margin: 5px 0;padding: 5px;width: 300px;}
.pagi_label img {float: left;height: 70px;padding:1px;margin: 0 5px 3px;width: 70px;}
.pagi_label h6, .pagi_label h6 a {margin:0;font-size:12px !important;font-weight:normal !important;color:#069}
.pagi_label:hover {-moz-box-shadow: 0px 0px 60px #505961 inset;}
.pagi_label p {font-size:12px;padding:0 3px 3px}
#loading_script {color:#888;font-family:Century Gothic;font-size:100px;letter-spacing:-10px;text-align:center;text-shadow:-5px 0 1px #444; background: #ffffff url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyUUylTS_HgpIkoqRvUhxL_3RsvBs8gJyShjpAzOV_9z1_sE9eHue9vvoo7fIKLZ_bS_Hn0UuxY5Hw74bq9OjATEp2rwmaYuvppaqMiH6hrBc7sFz7s0wBBubb9HgdCzWzW-PbEGpYC0c/) no-repeat 50% 50%; height:489px; width:100%}
#PR_Label_Sidebar {background-color: #ffffff;color: #BBB;font-family: Tahoma;font-size: 18px;text-align: center;margin:0 auto;width:100%}
#PR_Label_Sidebar a {color: #BBB !important;font-family: Tahoma !important;font-size: 18px !important;font-weight: normal !important;padding: 5px 10px;display:block;}
#PR_Label_Sidebar a:hover {color: #069 !important;}
#PR_Label_Sidebar span {padding: 5px 10px;}
#PR_Label_Sidebar span.disabled {color: #666 !important;}
#PR_Label_Sidebar .next {float:right;}
#PR_Label_Sidebar .previous {float:left;}
#PR_Label_Sidebar .first {text-align:center;}
</style>
<div id="Sidebar_Label">
</div>
<div id="PR_Label_Sidebar">
</div>

Bước 2. Vào Mẫu >> Chỉnh sửa HTML. Dùng (Ctrl + F) tìm từ khóa "Bài cùng chủ đề" (tên tiện ích bạn vừa đặt) mà bạn mới đặt tên cho Widget của tiện ích rồi thay nó thành như sau (phần đánh dấu màu đỏ là phần thêm vào):


<b:widget id='HTML1' locked='false' title='Bài cùng chủ đề' type='HTML'>
<b:includable id='main'>
<b:if cond='data:blog.pageType == &quot;item&quot;'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != &quot;&quot;'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>
<b:include name='quickedit'/>
</b:if>
</b:includable>
</b:widget>

Bước 3. Tìm đoạn code này <b:loop values='data:post.labels' var='label'>

Rồi thay thế nó bằng đoạn code này :

<b:loop values='data:post.labels' var='label'>
<script>var label_Related=&quot;<data:label.name/>&quot;;</script>

Lưu Lại và hoàn thành
0

Code ẩn bài đăng trên trang chủ blogger/ blogspot

Blogger cho phép bạn tùy chọn hiển thị số bài đăng trên trang chủ bằng cách sửa cài đặt blog. Nhiều nhất là 500 và ít nhất là 1.

Nhưng trong 1 số trường hợp bạn muốn ẩn tất cả bài đăng trên trang chủ của blog để nhằm hiển thị các nội dung khác mà bạn nghĩ nó quan trọng hơn bài đăng như là hiển thị các tiện ích bài đăng theo nhãn chẳng hạn.

Cách thực hiện:

- Vào bảng điều khiển blogger, chọn Chủ đề (Layout).
- Nhấp vào nút "Chỉnh sửa HTML" (Edit HTML).
- Dán đoạn mã dưới đây vào ngay sau đoạn mã này ]]></b:skin> :

<b:if cond='data:blog.url == data:blog.homepageUrl'>
<style type='text/css'>
.post, #blog-pager {display:none;}
</style>
</b:if>

- Cuối cùng, nhấp Lưu Lại chủ đề.

* Nếu bạn muốn ẩn sidebar, chân trang thì dùng thêm đoạn mã này:
<b:if cond='data:blog.url == data:blog.homepageUrl'>
<style type='text/css'>
.post, .footer, .post-footer, .feed-links, .post-title, .sidebar #blog-pager {display:none;}
</style>
</b:if>

0