iGoogler 优化教程(四):手写侧边栏提速

这个教程主要是方便和我一样使用 iGoogler 主题的人,能给自己的站点提一下速。因为一个效率优化做得那么好的主题,如果你还觉得速度慢,那真的是你不会使用了。WordPress 小工具其实是速度变慢的根源之一,因为这会引发许许多多的数据查询。所以,尝试自己手写 SideBar 吧,这并不难。而且,这样也有利于我们使用 WordPress Transients APIWordPress Object Cache 等缓存。

如果你不会写,那么可以参考我的:

打开主题的 sidebar_l.php,全部替换为:

<h3 class="lbar_title">
	<a><?php _e('分类目录')?> </a>
</h3>
<div class="lbar_content">
	<ul>
		<?php wp_list_categories('show_count=1&hierarchical=1depth=2&title_li='); ?>
	</ul>
</div>
<h3 class="lbar_title">
	<a><?php _e('时间选择');?> </a>
</h3>
<div class="lbar_content">
	<ul>
		<?php wp_get_archives(); ?>
	</ul>
</div>
<h3 class="lbar_title">
	<a><?php _e('标签云')?> </a>
</h3>
<div class="lbar_content">
	<ul>
		<?php wp_tag_cloud('smallest=10&largest=14&number=20&order=RAND'); ?>
	</ul>
</div>
<h3 class="lbar_title">
	<a class="current"><?php _e('友情链接')?> </a>
</h3>
<div class="lbar_content" style="display:block;">
	<ul>
		<?php wp_list_bookmarks('title_li=&categorize=0');?>
	</ul>
</div>
<div class="line"></div>

打开主题的 sidebar_r.php,全部替换为:

<h3>最新文章</h3>
<ul>
	<?php echo get_latest_posts_igoogler(5); ?>
</ul>
<h3>随便看看</h3>
<ul>
	<?php echo get_random_posts_igoogler(5); ?>
</ul>
<h3>最受欢迎</h3>
<ul>
	<?php
	$most_comments_posts_data = get_transient('most_comments_posts');
	if(false === $most_comments_posts_data){
		$most_comments_posts_data = get_most_comments_posts_igoogler(5);
		set_transient('most_comments_posts', $most_comments_posts_data, 86400);
	}
	echo $most_comments_posts_data;
	?>
</ul>

效果可参考本站。

此文章是由nikbobo发表在旧博客分类目录的。将固定链接加入收藏夹。

关于 nikbobo

Nikbobo,本名刘永强,记忆空间站长,男,1998 年出生于广东茂名,至今(2022 年)23 岁,目前(2022 年)就读于广州大学华软软件学院,常以“nikbobo”这个网名混迹互联网。如无特殊注明,Nikbobo 在本站发表的文章,遵循 知识共享 署名-非商业性使用-相同方式共享 4.0 国际 许可协议。详情请参阅关于页面的作者介绍。

发表回复

您的电子邮箱地址不会被公开。