logo
  • menu
  • menu
  • menu
  • menu

You're Browsering Archive for the ‘wordpress’ Tag

WP Plugin: Random Images

没想到我竟然会自己弄了一个Wordpress插件。这个插件我把它叫做Random Images,因为我是以random、image这两个关键字,在Snipplr Code 2.0里找到这个插件的核心代码—Simple PHP Randomizer的。它的功能,顾名思义,就是随机显示图片。效果见H!Beauty侧栏。

下载(donwload): Random Images 0.1

使用的话,我还没弄懂如何在后台添加设置界面,所以目前只能是通过后台的Plugin Editor手工修改了。还好,修改起来不算麻烦。点击这里可以查看完整的代码
下面这一串代码记录随机图片的信息,如链接、图片链接等,只要照着输入就可以了。加入更多图片的话,只需自行添加array,4、5、6….这样就可以了。

  1. 1 => array(
  2. 'href' => '链接',
  3.  'title' => '链接名',
  4.  'src' => '图片链接',
  5.  'alt' => '图片alt属性值'
  6. ),
  7. 2 => array(
  8. 'href' => 'url',
  9.  'title' => 'text',
  10.  'src' => 'image-url',
  11.  'alt' => 'text'
  12. ),
  13. 3 => array(
  14. 'href' => 'url',
  15.  'title' => 'text',
  16.  'src' => 'image-url',
  17.  'alt' => 'text'
  18. ),
  19. // add more data here

随机显示几张图片则修改下面代码中的阿拉伯数字即可。

  1. $numberOfItems = 2; // Change to the number of items you want show

Ok,大功告成。哎,其实只是简单的拼凑。

重写模板

拖拉了一个多星期,终于把模板代码重写了一遍。变化不大,只是把两栏改成三栏,配色还是以前那样。重写代码主要是小考一下自己的CSS知识,Wordpress函数方面,因为官方文档写得很详细,没费多少功夫。这次弄清了functions是干嘛使的,自然也加上了widget。觉得widget不好用,还是直接把代码加在侧栏里舒服:-)。

打算提供一个可下载的版本,只是不知道要拖拉到什么时候。

最后老规矩,附图一张。(大家都是通过RSS看博客吧:lol:)

rebuildtheme

用Feed Count显示Feedbuner订阅数

feedcount2Feedbuner被墙以后,那个显示订阅数的chicklet就显示不了了。Feed Count这个Wordpress插件是用文本方式显示Feedburner订阅数。它是用Feedburner的Awareness API提供的数据,也就是用api.feedburner.com/xxx的域名,而这个域名并没有被墙,所以用这个插件就可以在Blog里显示Feedburner的订阅数了。

把下面语句插入到模板中就可以了,也可以写一段CSS让它按你喜欢的方式显示。

  1. <?php if (function_exists('fc_feedcount')) fc_feedcount(); ?>

我的订阅数实在不好意思拿出来献丑,只有贴张后台选项截图。
feedcount

下载Feed Count1.2

Wordpress 2.3 Tag Archive

我想在存档(Archive)页面上加上一条提示信息,如“您正在浏览Tag为Wordpress的存档页面”,或“您正在浏览2007年11月的存档页面”。看了Codex文档,知道要用is_tag+single_tag_title组合,不过加进Theme里去费了一些时间。看来自己还是PHP白痴,所以记录一下。

首先Theme里得有个Archives(archive.php),当然没有也可以,加在Main Index Template(index.php)里也行。我这个Theme没有archive.php,而有了archive.php后,所有存档页包括月、年、分类等都会调用它来显示,Tag也是如此。判断是哪种存档页并显示相应的提示信息需要下面的语句(来自WP Glass):

  1. <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
  2. <?php /* If this is a category archive */ if (is_category()) { ?>
  3. <h3>You're Browsering Archive for the '<?php echo single_cat_title(); ?>' Category</h3>
  4. <?php /* If this is a tag archive */ } elseif (is_tag()) { ?>
  5. <h3>You're Browsering Archive for the ‘<?php echo single_tag_title(); ?>’ Tag</h3>
  6. <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
  7. <h3>You're Browsering Archive for <?php the_time('F jS, Y'); ?></h3>
  8. <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
  9. <h3>You're Browsering Archive for <?php the_time('F, Y'); ?></h3>
  10.  
  11. <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
  12. <h3>You're Browsering Archive for <?php the_time('Y'); ?></h3>
  13.  
  14. <?php /* If this is a search */ } elseif (is_search()) { ?>
  15. <h3>Search Results</h3>
  16. <?php /* If this is an author archive */ } elseif (is_author()) { ?>
  17. <h3>Author Archive</h3>

上面的语句加在if while语句–也就是下面两句之间

  1. <?php if (have_posts()) { ?>
  2. <?php while (have_posts()) : the_post(); ?>

现在提示信息就能“自动判断”显示了。不过Theme里有tag.php的话,Tag存档页是调用tag.php,可以在其中你希望显示的位置加上single_tag_title。

  1. You're Browsering Archive for the ‘<?php echo single_tag_title(); ?>’ Tag

OneClick - 后台直接上传插件和主题的WP插件

OneClick是一个简化Wordpress Plugins和Theme安装的插件。安装后可以直接在后台上传打成zip包的Plugins和Theme,并一键安装。在没有terminal登录的情况下,省去了下载、用FTP软件登录上传的烦琐步骤。

screenshot008vn0

Back to Blogger

再换回Blogger是不现实的。于是只能换用这个基于Blogger经典模板的theme。这个由Blogger的Minima Black转换而来的wordpress theme是DarkNight 2.0,作者是David Chait。我喜欢白色的,就自己code成Minima White。自己觉得效果不错^__^。

最后为自己在上班时间做这种无聊的事忏悔一下。