Blogger和WordPress的倒序显示

Blogger和WordPress都可以通过一定的设置,变成一个只供自己查看的私人博客,相当于私人日记本,具体方法是,在博客设置里将其设置为只有作者才能查看,然后将博客设置为在一页内全部显示(比如设置单页文章1千篇),在博客安装一个倒序显示脚本,即可完成日记本的功能,可供导出和打印。

除了打印,还可以将内容复制到TXT文件里,在邮箱里发送到Kindle邮箱,然后在自己的Kindle上看,相当于看书的体验。

这里面的一个技术问题是如何在Blogger和WordPress里实现按照日期倒序显示(Reverse Post Order)。这里分别给出Blogger和WordPress实现倒序的方法。

在Blogger中,页脚点击“添加小工具”,添加“HTML/JavaScript”微件,之后在微件内容里插入如下代码:

<!– Start Post Reversal Code –>
<script type=’text/javascript’>
//<![CDATA[
// —————————————————————————————–
// Name : PRS – Post Reversal Script for Blogger – Version 1.0
// Author : David Yockey
// URL : techsquirrels.blogspot.com/2012/04/swapping-to-reverse-post-order-on.html
// —————————————————————————————–

 

// Temp variable used to shorten classname references
var cn;
// This function is called as needed in the main program below.
function ReversePosts(BlogPostContainer,PostClass) {
// Arguments:
// BlogPostContainer — The node containing the posts to be reversed.
// PostClass — The className of each of the posts in the container to be reversed.
// (may be a single name from among names in the class attribute of the posts)
// Flag for checking whether any posts are found
var found=false;
var BlogPosts = BlogPostContainer.childNodes; // May include text-nodes containing
// whitespace in addition to post-nodes
// Set index variables to top and bottom of BlogPosts list
var i=0;
var j=BlogPosts.length-1;
for( ; ; ) { // Start Endless Loop
// Find next Post from the top
while( (i < j) && (!(cn=BlogPosts[i].className) || !(cn.match(PostClass))) )
++i;
// Find next Post from the bottom
while( (i < j) && (!(cn=BlogPosts[j].className) || !(found=cn.match(PostClass))) ) // (see Footnote 1)
–j;
if( found && i < j ) {
// Swap Posts (see Footnote 2)
var tempi = BlogPosts[i].cloneNode(true); // Store a copy of Post i in tempi
var tempj = BlogPosts[j].cloneNode(true); // Store a copy of Post j in tempj

 

BlogPostContainer.replaceChild(tempi,BlogPosts[j]); // Replace Post j with Post i in tempi
BlogPostContainer.replaceChild(tempj,BlogPosts[i]); // Replace Post i with Post j in tempj
} else {
// Done
break; // Break out of Endless Loop
}
++i; –j;
}
}
// Footnote 1:
// If a post is found from one end, then a post must necessarily be found from the other.
// So, recording and later checking for a post from one end is sufficient to ensure that
// one was found from both.
//
// Footnote 2:
// At least in Firefox 11.0 on Fedora Linux, replacing a child directly with another child
// causes some text-nodes containing whitespace to be deleted. That node deletion messes up

 

// the positions of the posts in the BlogPosts list. This is avoided by cloning both posts
// rather than just one and replacing both posts from the cloned copies.
// *** MAIN POST REVERSAL PROGRAM ***
// Magic Words
var BlogWidget = ‘Blog1’;
var BlogPostContainerClass = ‘blog-posts’;
var BlogPostClass = ‘date-outer’;
var DatePostContainerClass = ‘date-posts’;
var DatePostClass = ‘post-outer’;
var Blog1 = document.getElementById(BlogWidget);
// Find the node containing the blog posts
var BlogPostContainer;
var x=0;
do {
BlogPostContainer = Blog1.childNodes[x++];
} while ( !(cn=BlogPostContainer.className) || !(cn.match(BlogPostContainerClass)) );
// Reverse different day posts
ReversePosts(BlogPostContainer,BlogPostClass);
// Reverse same day posts – Loop thru contents of BlogPostContainer to find each day’s posts
var BlogPosts = BlogPostContainer.childNodes;
for ( i = 0; i < BlogPosts.length; ++i ) {
// Check for an actual post-node rather than a text-node or such
if ( (cn=BlogPosts[i].className) && cn.match(BlogPostClass) ) {
var DatePostContainer;
x=0;
// Find the node containing the posts to be reversed for the current day being processed
do {
DatePostContainer = BlogPosts[i].childNodes[x++];
} while ( !(cn=DatePostContainer.className) || !(cn.match(DatePostContainerClass)) );
ReversePosts(DatePostContainer,DatePostClass);
}
}
//]]>
</script>
<!– End Post Reversal Code –>

之后保存,设置“主页上显示的博文数量上限”的数量,然后打开页面即可看到倒序的文章。

对于WordPress来说,操作起来比较简单,安装一个名为“Chronological Posts”的Plugin即可实现倒序文章。

从安全性来说,Blogger更为安全一些,谷歌帐号设置两步验证,在谷歌Blogger中写内容,然后设置只有自己只读,安装一个倒序显示脚本,然后复制到TXT文件里,在邮箱里发送到Kindle邮箱,然后在自己的Kindle上看,看完了就删,只要谷歌帐号不泄露,秘密的信息就不会泄漏。

来源:月光博客

文章为作者独立观点,不代表站长派立场,本文链接:https://zhanzhangpai.com/?p=509

免责声明:本站部分内容来源互联网整理,如有侵权请联系站长删除。站长邮箱:1245911050@qq.com

(0)
上一篇 2022年1月24日 下午1:36
下一篇 2022年1月25日 上午10:39

相关推荐

  • 美国FCC禁止华为中兴等五家中企在美国销售设备

    当地时间周五(11月25日),美国联邦通信委员会(FCC)宣布,禁止华为、中兴通讯、海康威视、海能达和浙江大华五家公司在美国销售设备。 FCC称这五家的产品“对美国国家安全构成不可…

    2022年11月29日
  • Google“有用内容更新”观察及应对

    作者:Zac 更新日期: 2022年09月21日 今天突然觉得应该写一下Google前些天刚上线的“有用内容更新”,因为感觉这个更新尤其清晰地显示着Google这两年的算法发展方向…

    2022年12月6日
  • 【SEM知识】同质化创意怎么变成新鲜创意

    很多优化师或许都遇到过,优质广告复制重上后难起量的问题,这很可能是因为广告被系统判断为同质化创意而遭受挤压,在我们需要优质广告继续拿量的时候,就需要明确,调整哪些内容,可以让系统判…

    2022年3月9日
  • cdn网站加速是什么意思

    cdn网站加速是什么意思 什么是cdn网站加速?cdn网站加速是干嘛的?哪些行业适合使用cdn加速服务?下面是有关cdn网站加速的知识介绍。 1、cdn网站加速是什么意思? CDN…

    2022年6月1日
  • web服务器有哪些种类?web服务器有什么作用?选购web服务器要注意什么?

    web服务器有哪些种类?web服务器有什么作用?选购web服务器要注意什么? 什么是web服务器?web服务器是什么意思?你知道web服务器有哪些种类吗?使用过国外虚拟主机建站的站…

    2022年4月11日
  • 网站流量变化认知误区

    1、Q:“索引量下降了” A:索引量并不等于流量,所以在索引量异常变化和下降时,不一定会带来流量变化。(索引资源库会不定期的更新,对无用户需求的资源进行删除更新。) 2、 Q:“流…

    2022年7月7日
  • 腾讯游戏管家PC端停止服务

    12月1日消息,腾讯游戏管家今天表示,因业务运营策略调整,2022年12月31日起腾讯游戏管家PC端将停止服务。 据悉,腾讯游戏管家由腾讯网游加速器升级而来,是一款免费游戏加速管理…

    2022年12月5日
  • .club域名适合哪些终端企业建站?

    .club域名适合哪些终端企业建站? .club域名作为新通用顶级域名,英文直译有“俱乐部”得意思,相信大家都有所了解。现今随着.com域名的资源枯竭,所以很多公司开始用.club…

    2022年4月27日
  • 站长博客:域名到期怎么办?域名到期多久会被删除?

    域名到期了怎么办?有没有什么解决办法?由于域名是有期限的,因此域名到期都有存在一个周期,在这个周期快要结束的时候,有利于域名到期续费一事进行诈骗,因此多数人都想要找到域名到期续费的…

    2022年2月21日
  • 有阳了的站长吗?

    好吧我就是一个,昨天一起来明显感觉身上肌肉酸疼,有点发热,量了一下体温37.5,也没管。 到了中午就不行了,身上疼得厉害,头也疼,体温直接38.5,然后就吃布洛芬吧,然后多喝温水。…

    2022年12月12日