存档

文章标签 ‘Wordpress’

[郁闷]终于知道为啥12月12以来Google Analytics的数字骤降了……

2009年12月21日 Galaxy 1 条评论

因为手上有3个域名(galaxy001和galaxysd这2个3322的加网友送的galaxy.ourkernel.com),所以统计代码按 http://code.google.com/intl/zh-CN/apis/analytics/docs/tracking/asyncMigrationExamples.html 的,加了:

var pageTracker = _gat._getTracker('UA-XXXXX-X');
pageTracker._setDomainName('none');
pageTracker._setAllowLinker(true);
pageTracker._trackPageview();

(加的是中间2行)

由于我用了WP插件Google Analyticator,它的Version: 6.0.2是Last Updated: 2009-12-12,而ChangeLog是:

6.0.2
* Updates the async tracking snippet to the latest version provided by Google.

就是说,它已经是:

_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);

(中间2行在修改前是最开始那2行……)


解决就简单了,把pageTracker._set那套换成_gaq.push(['_set

唉,今天一上午翻wiki查资料,下午郁闷了,干点别的,就来G了下,不想就发现Google Analytics推出异步跟踪分析,看时间接近,查了下官方代码,再看看自己的博客页面,一切就都清楚了。
这段代码还是2009年3月份加的,都过了大半年了,Galaxy咋会记得……

[ZT]更新升级到WordPress 2.9及Simple Tags插件问题

2009年12月21日 Galaxy 没有评论

http://www.alexblair.org/user-alexblair-post-915.html
http://www.dreamfreeblog.com/2009/12/wordpress29.html

Simple Tags 插件问题,以前 WordPress 2.7 也出现过问题…这次 WordPress 2.9 提示:

Simple Tags can’t work with this WordPress version!

“Simple Tags 插件不能在当前 WordPress 版本工作”,其实也算不上不兼容,是插件作者多了一个 WordPress 版本强行检查的注释,最高版本检查 wp 2.8 已经写死(hard-coded)在里面了,还没来得及更新。解决方法,只要找到:

    if ( strpos($wp_version,2.7) !== false || strpos($wp_version,2.8) !== false) {

修改成:

    if ( strpos($wp_version,2.7) !== false || strpos($wp_version,2.8) !== false || strpos($wp_version,2.9) !== false ) {

嘛,Galaxy就直接把2.72.9了……

分类: Wordpress 标签: ,

[ZT]WordPress 的 RSS feed

2009年6月13日 Galaxy 没有评论

http://www.neoease.com/wordpress-rss-feed/
June 11th, 2009
可能你知道 WordPress 向你提供的那几个关于 Feed 调用的方法, 并知道如何在主题中插放你的 RSS 或者 Atom. 但你应该知道更多, 因为这些 Feed 可以向你提供很多的便利.

如果你知道 WordPress 的订阅链接规则, 那么就算人家不向你提供订阅链接, 你也可以订阅他的博客内容. 并可以通过它们订阅一些你感兴趣的内容. 你可以通过分类订阅, 通过标签订阅, 甚至对搜索结果进行订阅.

阅读全文…

分类: Wordpress 标签: , ,

解决:Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate xxx bytes)

2009年6月12日 Galaxy 4 条评论

http://wordpress.org/support/topic/194370

Here’s the full solution in the cleanest possible way:

  1. Create a file called php.ini in the root of your site (if you are using a hosted addon domain, this must be in the subdirectory of that site)
  2. In php.ini, enter a line that says
    memory_limit = 64MB
  3. In your site’s .htaccess (being a WordPress blog, I’m assuming there is one), enter the following line
    SetEnv PHPRC /<unix path to the directory where php.ini is>/
    (keep the slashes)
  4. Edit wp-config.php and enter the following line
    define('WP_MEMORY_LIMIT', '64M');
  5. Upload the new files to the server

Oh, and don’t tell your hosting provider you’ve done this…


这次升级2.8后,就要在wp-config.php中加define ('WP_MEMORY_LIMIT', '64M');了……

分类: Wordpress 标签: ,

[ZT]一個 WordPress plugin 的 debug 過程

2009年5月23日 Galaxy 没有评论

http://blog.chweng.idv.tw/archives/300

這是一個與 WordPress 插件 bug 奮鬥的流水帳,有興趣的人再看看就好,其他人就可以直接跳過啦!

阅读全文…

分类: Wordpress 标签: ,

[ZT]使用jQuery为导出链接增加favicon图标

2009年5月22日 Galaxy 没有评论

http://xiao3meng.org/web/use-jquery-increase-favicon-icon/
今天在我的博客上在家里一个小功能,就是所有导向其他网站的链接都会有对应网站的 Favicon 图标显示,譬如这个链接到 Google 的。

导出链接 Favicon 标记是通过 jQuery 实现的,代码来自于 exscale.se ,可以设置最对某段 div 起作用,并且对于无法获取 favicon.ico 的网站采用默认的导出链接图片标示。这样设置以后,在别人阅读你的文章的时候,效果很明显。

如果你也想在自己的网站上实现该效果,可以直接下载一个 JS 文件,添加到底部,并且加上一段控制作用区域的代码如下:

<script type='text/javascript'>
 jQuery('.post').favicons({defaultIco: 'http://xiao3meng.org/wordpress/wp-content/themes/inove/img/external.gif'});
</script>

注意:其中 .post 部分是我网站上的目标区域,你需要更改成自己的。
下载 :
jqueryfavicons.js

分类: Wordpress 标签: , ,

[ZT]WordPress的几个杀手级Hack技巧

2009年4月20日 Galaxy 没有评论

WordPress的10个杀手级Hack技巧

http://xiao3meng.org/wrodpress/wordpresss-10-killer-techniques-hack/
二月 12th, 2009

这篇文章将向大家介绍10个最新最实用的WordPress hack,它能让你的博客引擎开足马力,挣脱束缚,最大限度地为你服务。此外,每个hack还都附有相关说明,这样你不仅能让WordPress释放最大力量,还能知道如何操作。

1.只在搜索引擎结果中显示AdSense 广告

问题:众所周知,一般访问并不点击广告。广告点击率90%是来自搜索引擎的显示结果。另一个问题是Google 的智能计价。智能定价意味着CTR比较低,点击率单价大打折扣。例如,如果一次点击正常获得1美元的话,Google的智能计价只会是0.1美元。郁闷吧?但是,以下的代码改进就能解决这个问题了。它只在搜索引擎结果中显示AdSense 广告,这意味着你能得到更多的点击率,更高的CTR.

解决方案:

  1. 打开主题中的functions.php文件。
  2. 粘贴进下代码:
    function scratch99_fromasearchengine(){
    $ref = $_SERVER['HTTP_REFERER'];
    $SE = array(/search?’, ‘images.google., ‘web.info.com’, ’search., ‘del.icio.us/search’, ’soso.com’,/search/,.yahoo.);
    foreach ($SE as $source) {
    	if (strpos($ref,$source)!==false) return true;
    }
    	return false;
    }
  3. 把以下代码粘贴到AdSense广告显示位置的相应模板中。它只会在搜索引擎结果中显示:
    if (function_exists(’scratch99_fromasearchengine’)) {
    	if (scratch99_fromasearchengine()) {
    		INSERT YOUR CODE HERE
    	}
    }

代码说明:这个改进以scratch99_fromasearchengine()函数开头,包括了用来指定搜索引擎的$SE数组变量。这样,只要把新元素加入到数组中就能轻松添加新的搜索引擎。如果使用搜索引擎搜索的访客包含了$SE数组变量,scratch99_fromasearchengine()接着就会返回true值。

2.避免在多循环中出现重复文章

问题:由于“杂志型”主题的流行,现在很多WordPressy用户在他们的首页上都使用了多个循环,因此他们也迫切需要在第二个循环上避免出现重复文章。
解决方案:使用PHP数组就能轻松解决这一问题

  1. 创建一个PHP数组,并把第一个循环的所有文章ID放在其中
    <h2>Loop n°1</h2>
    < ?php
    $ids = array();
    while (have_posts()) : the_post();
    the_title();
    ?>
    <br />
    < ?php $ids[]= $post->ID;
    endwhile; ?>
  2. 对于第二个循环:使用PHP函数in_array()来检查$ids数组中是否包含了某个文章ID。如果这个文章ID没有包含在此数组中,意味着第一个循环中没有此篇文章,那么系统就可以显示它了。
    <h2>Loop n°2</h2>
    < ?php
    query_posts(”showposts=50);
    while (have_posts()) : the_post();
    if (!in_array($post->ID, $ids)) {
    the_title();?>
    <br />
    < ?php }
    endwhile; ?>

代码说明:执行第一个循环时,其中的所有文章ID都会被放到一个数组变量中。因此,第二个循环执行时,我们只要到这个数组中检查当前的文章ID是否已显示在第一个循环中就可以了。

3.用页码代替“上页”和“下页”

问题:WordPress有默认函数来显示上页和下页页面,虽然这比没有这个什么功能好,但是我不明白开发人员为什么不把页面写进核心代码呢。当然,我们可以用插件来生成页码,但是如果能把页码直接插入主题岂不更好?!
解决方案:这里使用WP-PageNavi插件把页码直接写入主题

  1. 首先下载WP-PageNavi插件
  2. 在硬盘驱动上解压插件存档,并把wp-pagenavi.php 和 wp-pagenavi.css文件上传到主题目录
  3. 打开要放置页码的文件(如index.php, categories.php, search.php,等),找到以下代码:
    <div class=”navigation”>
    <div class=”alignleft”><?php next_posts_link(’Previous entries’) ?></div>
    <div class=”alignright”><?php previous_posts_link(’Next entries’) ?></div>
    </div>
    用以下代码代替以上内容:
    <?php
    include(’wp-pagenavi.php’);
    if(function_exists(’wp_pagenavi’)) { wp_pagenavi(); }
    ?>
  4. 接着请修改插件文件。打开wp-pagenavi.php文件并找到以下代码(61行):
    function wp_pagenavi($before = ”, $after = ”) {
    global $wpdb, $wp_query;
    修改成:
    function wp_pagenavi($before = ”, $after = ”) {
    global $wpdb, $wp_query;
    pagenavi_init(); //Calling the pagenavi_init() function
  5. 最后,我们要把wp-pagenavi样式表添加到博客。
    打开header.php 文件,把以下代码添加进去:
    <linkrel=”stylesheet”href=”<?phpechoTEMPLATEPATH.’/pagenavi.css’;?>”type=”text/css”media=”screen”/>

代码说明:这个代码改进直接在主题文件中加入添加了插件代码。我们另外还调用了pagenavi_init()函数以使页码能够正常显示。

4.自动获取文章图像

问题:使用自定义字段来显示和日志相关的图像固然很好,但是许多用户想直接检索并使用文章本身嵌入的图像。

解决方案: 至今为止,还没有这样的插件。值得庆幸的是,以下循环将帮我们解决这一问题:它会搜索文章内容的图像并把它们显示出来

  1. 把以下代码粘贴到主题文件任意位置:
    < ?php if (have_posts()) : ?>
    < ?php while (have_posts()) : the_post(); ?>
    < ?php
    $szPostContent = $post->post_content;
    $szSearchPattern = ‘~<img [^\/>]*\ />~’;
    // Run preg_match_all to grab all the images and save the results in $aPics
    preg_match_all( $szSearchPattern, $szPostContent, $aPics );
    // Check to see if we have at least 1 image
    $iNumberOfPics = count($aPics[0]);
    if ( $iNumberOfPics > 0 ) {
    // Now here you would do whatever you need to do with the images
    // For this example the images are just displayed
    	for ( $i=0; $i < $iNumberOfPics ; $i++ ) {
    		echo $aPics[0][$i];
    	};
    };
    endwhile;
    endif;
    ?>

代码说明:以上代码实际上包含了一个WordPress循环。使用PHP和正则表达式的唯一区别就是前者会自动搜索文章内容中的图像而不是仅仅显示文章。一旦发现图像,系统就会显示。


阅读全文…

分类: Wordpress 标签: , ,

[ZT]WordPress Backup to FTP

2009年4月5日 Galaxy 没有评论

http://www.guyrutenberg.com/2009/01/06/wordpress-backup-to-ftp/

WordPress Backup to FTP

with 9 comments

This script allows you to easily backup your WordPress blog to an FTP server. It’s actually a modification of my WordPress Backup to Amazon S3 Script, but instead of saving the backup to Amazon S3 it uploads it to an FTP server. Another update is that now the SQL dump includes the database creation instructions so you don’t need to create it manually before restoring from the backup.

Although I’ve written it with WordPress in mind (to creates backups of my blog), it isn’t WordPress specific. It can be used to backup any website that consists of a MySQL database and files. I’ve successfully used it to backup MediaWiki installation.

#!/bin/bash
 
# (C) 2008 Guy Rutenberg
# This is a script that creates backups of my blog.
 
DB_NAME=guy_blog
DB_USER=******
DB_PASS=******
DB_HOST=localhost
 
BLOG_DIR=/home/guyru/guyrutenberg.com/
BACKUP_DIR=/home/guyru/backups/
 
FTP_HOST=88.198.42.4
FTP_USER=******
FTP_PASS=******
FTP_BACKUP_DIR=guyru/
 
# end of configuration - you probably don't need to touch anything bellow
BLOG_DIR=`dirname "$BLOG_DIR"`/`basename "$BLOG_DIR"`
BACKUP_DIR=`dirname "$BACKUP_DIR"`/`basename "$BACKUP_DIR"`
 
echo -n "dumping database... "
DUMP_NAME=${DB_NAME}-$(date +%Y%m%d).sql.bz2
mysqldump --user=${DB_USER} --password=${DB_PASS} --host=${DB_HOST} \
 --databases ${DB_NAME} \
 | bzip2 -c > ${BACKUP_DIR}/${DUMP_NAME}
if [ "$?" -ne "0" ]; then
	echo "failed!"
	exit 1
fi
echo "done"
 
echo -n "Creating tarball... "
TAR_NAME=${BLOG_DIR##*/}-$(date +%Y%m%d).tar.bz2
tar -cjf ${BACKUP_DIR}/${BLOG_DIR##*/}-$(date +%Y%m%d).tar.bz2 ${BLOG_DIR}
if [ "$?" -ne "0" ]; then
	echo "failed!"
	exit 2
fi
echo "done"
 
echo -n "Uploading SQL dump and tarball to FTP... "
lftp -u ${FTP_USER},${FTP_PASS} ${FTP_HOST} <<EOF
cd "${FTP_BACKUP_DIR}"
put "${BACKUP_DIR}/${DUMP_NAME}"
put "${BACKUP_DIR}/${TAR_NAME}"
 
EOF
if [ "$?" -ne "0" ]; then
	echo "failed!"
	exit 3
fi
echo "done"

The configuration is done using the variables in the beginning of the script (until the “end of configuration” line). They are pretty self explanatory, and you should adjust them for your site before using the script. If there are variables you don’t understand what they do, see the post about the previous script, and don’t hesitate to comment.


I usually prefer to keep a copy of my backups on the server as an extra precaution. But if you want them to be removed after a successful FTP upload, just append the following to the script:

rm -f "${BACKUP_DIR}/${DUMP_NAME}"
rm -f "${BACKUP_DIR}/${TAR_NAME}


Copy the above code and save it to a file called backup-blog. Before you can use it there are some configurations to be done. At the beginning of the script (right after the copyright notice), you will find some variable you need to set.

The first set of variables is the database configuration. Set DB_NAME to the name of your database, DB_USER to your database username, DB_PASS to the user’s password and DB_HOST to the hostname of the database server. For most users the DB_HOST should be set for localhost (but some users need to specify a different value here).

The next variable is BLOG_DIR. Set it to the full path of the directory where you installed WordPress. BACKUP_DIR should be set to the full path of the directory you to keep the backups in, make sure the user which will run the script has write access to it. Notice that both paths shouldn’t end with a trailing ‘/’ (slash).

Now that the configuration is over, make the script executable:
chmod +x backup-blog
Now you can test that everything works ok by running the script: ./backup-blog. If the script failed for some reason make sure your configuration is correct.

The next step is to automate the backup process using cron. Run crontab -e to add an entry to the backup script. Append the following line to the crontab:
30 1 * * 4 /path/to/backup-blog
This will run the script automatically for you once a week, on 01:30 AM every Friday. Be sure to check up the backup folder from time to time to make sure everything is running smooth.

Note that while the script was originally intended to create backups of WordPress blogs it can also be used to backup any kind of website that needs both files and database backups, like MediaWiki, Drupal, or almost any kind of CMS and blogging platform.

分类: Wordpress 标签: ,
Locations of visitors to this page