存档

‘折腾北瓜’ 分类的存档

Configure SMTP解决WordPress用户注册和评论邮件通知收不到邮件的问题

2009年10月23日 IT北瓜 3 条评论

      前两天安装了ThinkAgainMail To Commenter插件,可是发现评论回复收不到邮件通知,用插件自带的邮件发送测试发送的邮件也收不到。期间询问了ThinkAgain,他也热心的给了我回复,但是问题还是没有解决。同时还发现用户注册后收不到发送密码的邮件。博客的主机是在酋长那购买的,是Linux的,按道理发邮件是不会有什么问题的。一时间真是举手无措,后来找到了Configure SMTP这款插件,总算把问题解决了。邮件的使用很简单,这里就不多做阐述了,记录一下,给遇到同样问题的博主们做下参考。

(CSS专题)给标题加上阴影效果

2009年10月20日 IT北瓜 没有评论

      自从Firefox 3.1发布之后,4大浏览器中已有3个支持CSS的text-shadow属性,唯独IE浏览器尚不支持。利用text-shadow可以轻而易举的实现文字的阴影从而产生立体效果。例如:IT北瓜博客的text-shadow为:

h1, h2, h3, h4, h5, h6 {
    font-weight:bold;
    letter-spacing:-0.05em;
    font-family:"微软雅黑",Arial;
    text-shadow: 1px 1px 2px #999;/*这里就是阴影效果*/
}

具体效果见本博客。

      由于IE不支持text-shadow属性,所以这里顺便介绍一款可以在IE下实现阴影效果的jQuery插件Text-shadow in IE with jQuery,但插件的作者也提到了该插件还有一些bug。

iNove主题非插件利用jQuery实现Ajax评论

2009年9月20日 IT北瓜 64 条评论

      刚开始使用Quick Comments插件效果很好,这也是iNove主题作者mg12推荐的插件之一。但后来不知道怎么回事发现提交评论总是跳转到另一个页面,卸载重装该插件问题还是没有解决,有可能是装其他插件给弄成这样的。但不管到底是怎么回事,现在用不了总得小办法解决。既然插件不行,那么就试试看非插件方式吧。于是找到了Xiaorsz的这篇文章使用 jQuery 实现 wordpress 的 Ajax 留言,沿用了他的代码,做了一点细微的修改。总算恢复了ajax评论功能。

      具体代码:

      comments-ajax.php:

<?php
if ($_SERVER["REQUEST_METHOD"] != "POST") {
    header('Allow: POST');
    header("HTTP/1.1 405 Method Not Allowed");
    header("Content-type: text/plain");
    exit;
}
$db_check = true;
function kill_data() {
    return '';
}
function check_db() {
    global $wpdb, $db_check;
    if($db_check) {
        // Check DB
        if(!$wpdb->dbh) {
            echo('Our database has issues. Try again later.');
        } else {
            echo('We\'re currently having site problems. Try again later.');
        }
        die();
    }
}
ob_start('kill_data');
register_shutdown_function('check_db');
require_once(dirname(__FILE__)."/../../../wp-config.php");
$db_check = false;
ob_end_clean();
nocache_headers();
function fail($s) {
    header('HTTP/1.0 500 Internal Server Error');
    echo $s;
    exit;
}
$comment_post_ID = (int) $_POST['comment_post_ID'];
$status = $wpdb->get_row("SELECT post_status, comment_status FROM $wpdb->posts WHERE ID = '$comment_post_ID'");
if ( empty($status->comment_status) ) {
    do_action('comment_id_not_found', $comment_post_ID);
    fail('The post you are trying to comment on does not currently exist in the database.');
} elseif ( 'closed' ==  $status->comment_status ) {
    do_action('comment_closed', $comment_post_ID);
    fail('Sorry, comments are closed for this item.');
} elseif ( in_array($status->post_status, array('draft', 'pending') ) ) {
    do_action('comment_on_draft', $comment_post_ID);
    fail('The post you are trying to comment on has not been published.');
}
$comment_author       = trim(strip_tags($_POST['author']));
$comment_author_email = trim($_POST['email']);
$comment_author_url   = trim($_POST['url']);
$comment_content      = trim($_POST['comment']);
// If the user is logged in
$user = wp_get_current_user();
if ( $user->ID ) {
    $comment_author       = $wpdb->escape($user->display_name);
    $comment_author_email = $wpdb->escape($user->user_email);
    $comment_author_url   = $wpdb->escape($user->user_url);
    if ( current_user_can('unfiltered_html') ) {
        if ( wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $_POST['_wp_unfiltered_html_comment'] ) {
            kses_remove_filters(); // start with a clean slate
            kses_init_filters(); // set up the filters
        }
    }
} else {
    if ( get_option('comment_registration') )
        fail('Sorry, you must be logged in to post a comment.');
}
$comment_type = '';
if ( get_option('require_name_email') && !$user->ID ) {
    if ( 6> strlen($comment_author_email) || '' == $comment_author )
        fail('Error: please fill the required fields (name, email).');
    elseif ( !is_email($comment_author_email))
        fail('Error: please enter a valid email address.');
}
if ( '' == $comment_content )
    fail('Error: please type a comment.');
// Simple duplicate check
$dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND ( comment_author = '$comment_author' ";
if ( $comment_author_email ) $dupe .= "OR comment_author_email = '$comment_author_email' ";
$dupe .= ") AND comment_content = '$comment_content' LIMIT 1";
if ( $wpdb->get_var($dupe) ) {
    fail('Duplicate comment detected; it looks as though you\'ve already said that!');
}
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID');
$comment_id = wp_new_comment( $commentdata );
$comment = get_comment($comment_id);
if ( !$user->ID ) {
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    setcookie('comment_author_url_' . COOKIEHASH, clean_url($comment->comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
}
@header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
$comment->comment_type = 'comment';
$comment_index = $_POST['comment_count'] + 1;
?>
<li class="comment <?php if($comment->comment_author_email == get_the_author_email()) {echo 'admincomment';} else {echo 'regularcomment';} ?>" id="comment-<?php comment_ID() ?>">
		<div class="author">
			<div class="pic">
				<?php if (function_exists('get_avatar') && get_option('show_avatars')) { echo get_avatar($comment, 51); } ?>
			</div>
			<div class="name">
				<?php if (get_comment_author_url()) : ?>
					<a id="commentauthor-<?php comment_ID() ?>" class="url" href="<?php comment_author_url() ?>" rel="external nofollow">
				<?php else : ?>
					<span id="commentauthor-<?php comment_ID() ?>">
				<?php endif; ?>

				<?php comment_author(); ?>

				<?php if(get_comment_author_url()) : ?>
					</a>
				<?php else : ?>
					</span>
				<?php endif; ?>
			</div>
		</div>

		<div class="info">
			<div class="date">
				<?php printf( __('%1$s at %2$s', 'inove'), get_comment_time(__('F jS, Y', 'inove')), get_comment_time(__('H:i', 'inove')) ); ?>
					 | <a href="#comment-<?php comment_ID() ?>"><?php printf('#%1$s', ++$commentcount); ?></a>
			</div>
			<div class="act">
				<a href="javascript:void(0);" onclick="MGJS_CMT.reply('commentauthor-<?php comment_ID() ?>', 'comment-<?php comment_ID() ?>', 'comment');"><?php _e('Reply', 'inove'); ?></a> |
				<a href="javascript:void(0);" onclick="MGJS_CMT.quote('commentauthor-<?php comment_ID() ?>', 'comment-<?php comment_ID() ?>', 'commentbody-<?php comment_ID() ?>', 'comment');"><?php _e('Quote', 'inove'); ?></a>
				<?php
					if (function_exists("qc_comment_edit_link")) {
						qc_comment_edit_link('', ' | ', '', __('Edit', 'inove'));
					}
					edit_comment_link(__('Advanced edit', 'inove'), ' | ', '');
				?>
			</div>
			<div class="fixed"></div>
			<div class="content">
				<?php if ($comment->comment_approved == '0') : ?>
					<p><small><?php _e('Your comment is awaiting moderation.', 'inove'); ?></small></p>
				<?php endif; ?>

				<div id="commentbody-<?php comment_ID() ?>">
					<?php comment_text(); ?>
				</div>
			</div>
		</div>
		<div class="fixed"></div>

      comments.js:

$(document).ready(function() {
if ($('#commentform').length > 0) {
    $('#commentform').submit(function(){    //ID为 commentform 的表单提交时发生的函数,也就是整个留言输入框 form 的ID。
        jQuery.ajax({
            url: '/wp-content/themes/inove/comments-ajax.php',    //刚刚创建的 comments-ajax.php 文件的位置,建议用绝对路径。
            data: $('#commentform').serialize(),
            type: 'POST',
            beforeSend: function() {
            $('#commenterror').hide();
            var submit='<div id="commentload" style="display: none;;margin: 0 auto;text-align:center;"><img src="/wp-content/themes/inove/img/ajax-loader.gif" />评论提交中,请稍后...</div>';    //创建名为 submit 的字符串,稍后插入,这里的样式大家自己根据需要定义,那个背景图片自己去下哈。
	     var error='<div id="commenterror" style="display: none;margin: 0 auto;text-align:center;"></div>';    //创建名为 error 的字符串
	        $('#comments').after(submit);    // 在ID为 comments 的元素后插入刚定义的 submit
	        $('#comments').after(error);    // 同样插入刚定义的 error
                $('#commentload').slideDown();  // 让submit 向下滑出
            },
            error: function(request) {    //发生错误时
                $('#commentload').hide();    //隐藏  submit
                $('#commenterror').show("slow").html(request.responseText); //显示 error
            },
            success: function(data) {
                $('textarea').each(function(){
                    this.value='';
                });
                $('#commenterror').hide().html();
                if (!$('#thecomments').length) {
                $('#pinglist').before('<ol id="thecomments"></ol>');}
                $('#thecomments').append(data);    //向ID为 thecomments 的元素添加数据,也就是整个 ol 或 ul
				var new_comment = $('#thecomments li:last').hide();    //让最新添加的数据隐藏
				new_comment.slideDown(1000);    //再显示,这里是为了实现滑出的效果,不想要也可以直接显示
                $('#commentform:input').attr('disabled', true);
                $('#commentload').slideUp("slow");
		$('#nocomment').slideUp("slow");    //这是针对我模版而加的,因为我模版在没有留言时会有个 nocomment 的元素,我要让添加一条留言后他自动隐藏,要不然会矛盾,呵呵,这个可以自行选择要或不要
		setTimeout(function() {
                $('#commentform:input').removeAttr('disabled');
                }, 10000);        //这里是设置10秒之后才可以再次留言,自行设置,单位毫秒。
            }
        });
       return false;
   } );
}})

      不过还有一点小问题:

      1、刚提交的评论的序号总是#1,刷新页面后才能显示正常。

      2、管理员提交评论头像在左侧,在iNove主题中应该是在右侧才正确的,刷新页面后才能显示正常。根据Xiaorsz说可以将

<li class="comment <?php if($comment->comment_author_email == get_the_author_email()) {echo 'admincomment';} else {echo 'regularcomment';} ?>" id="comment-<?php comment_ID() ?>">

中的

get_the_author_email()

换成管理员的具体邮箱地址,不过我没有做测试,大家可以自己测试一下。

非插件方式添加评论表情

2009年9月15日 IT北瓜 没有评论

由于使用Auto HighSlide代替Highslide4WP,所以评论框下的表情符号也就没有了(停用了Highslide4WP)。虽然插入表情的插件有不少,但总觉得为了插入几个表情符号就去安装一个插件有点小题大做了。结果找到了Life Studio的Wordpress 非插件调用表情符,以下是我按照该文章所说的方法实现的具体效果:

红线框出来的部分就是刚才实现的效果啦。一直很喜欢QQ的表情,做得很逼真很Q!本来是要用QQ软件中的那套“圆脸”表情的,不过无意中在网上看到这套“方脸”的,觉得很有个性,就用上了。这套表情有22个,不过iNove主题中放22个就有一个表情换行了,所以我干脆就去掉了1个,只显示21个表情。

鼠标悬停显示 @ 评论

2009年9月15日 IT北瓜 没有评论

网站备案通过,安啦!!!

2009年9月15日 IT北瓜 2 条评论

IT北瓜网站备案通过啦,备案号“粤ICP备09166890号”。赶紧把备案号挂到页脚上,安啦!!!

使用Auto HighSlide代替Highslide4WP

2009年9月11日 IT北瓜 3 条评论

其实一直很喜欢mg12Highslide4WP,但是直接在WordPress后台撰写日志感觉比较麻烦,Highslide4WP的插入图片的操作也比较繁琐,所以现在一直用Windows live writer来写日志。不过有得必有失,这样一来,插入图片就没有Highslide特效了。不过我想既然有需求那就应该会有供应的,本来还想自己用jQuery写一个js文件来绑定onclick事件条用Highslide4WP插件,但后来想想这样也不是很方便,况且自己不懂php。结果通过Google搜索到了Showfom的这款插件Auto HighSlide,其中介绍说到这款插件是“Highslide4WP的精简加强版”,但这两款插件不能同时使用。于是停用了Highslide4WP而使用Auto HighSlide,效果如下:

点击前图片显示:

点击后图片显示:

这样不但以后写的日志可以有Highslide特效,以前写的日志同样也有,这款插件也支持键盘方向键操作,很不错,(*^__^*) 嘻嘻……

停用SMCF插件启用Meebo即时聊天

2009年9月11日 IT北瓜 没有评论

今天停用了SimpleModal Contact Form (SMCF)插件,嵌入了可爱的即时聊天工具Meebo,具体效果见本站的右边栏。登录Meebo之后,你不仅可以同时和 MSN、Y!M、Jabber/Gtalk以及AIM中的联系人进行交流,而且还能实时地和你的website/blog上的读者进行交流。

更换iNove主题标题为个性Logo

2009年9月1日 IT北瓜 2 条评论

      今天是IT北瓜运作的第3天,由于工作比较忙,IT北瓜的更新也较少,工作时间抽点时间再折腾一下(动作要快,给领导发现我不务正业就尴尬了,⊙﹏⊙b汗)。

那么折腾的什么呢?赶紧给北瓜挂上个Logo,比较人要脸树要皮嘛,O(∩_∩)O哈哈~

第一步:只做自己的Logo,就像北瓜这个,我自己瞎弄的,感觉还算不影响市容,+_+

logo

注:logo的背景是透明的,具体见IT北瓜顶部的Logo效果。顺道给各位提供个在线制作logo的网址http://free.logomaker.cn/,试了一下生成的是jpg文件,效果一般。

第二步:修改iNove主题中templates文件夹下的header.php,将:

<div id="caption">
    <h1 id="title"><a href="<?php bloginfo('url'); ?>/"><?php bloginfo('name'); ?></a></h1>
    <div id="tagline"><?php bloginfo('description'); ?></div>
</div>

修改为:

<div id="caption">
    <h1 id="title" class="img-title"><a href="<?php bloginfo('url'); ?>/"><?php bloginfo('name'); ?></a></h1>
    <div id="tagline"><?php bloginfo('description'); ?></div>
</div>

即为h1添加一个名为”img-title”的class

第三步:修改iNove主题样式style.css文件,在其末尾添加如下代码:

.img-title {
    background: url(img/logo.png) left top no-repeat;
    _background: url(img/logo.gif) left top no-repeat;
    width: 160px;
    height: 50px;
    text-indent: -999em;
}

注:由于IE下png背景图片透明效果会失效,因此加了这个代码

_background: url(img/logo.gif) left top no-repeat; 

这行代码只对IE6有效,IE7以上版本无效,也就是让它在IE6下用gif格式的logo文件作为背景,PS:当然效果较差。

既然现在用自己的logo来替换标题,那么文字标题就不应该让它再显示出来了,但如果我们直接把输出标题的代码

<?php bloginfo('name'); ?>

给去掉,这样会影响搜索引擎的友好性,这里利用了css中的缩进属性text-indent,给它一个足够大的负值,那它就会乖乖的躲起来不让你看到了,当然也有别的处理方法,比如在<a>标签中加入

style="width:0px; overflow: hidden;"

第四步:那就是上传更新了的文件header.php、style.css、logo.png、logo.gif,注意上传的目录。

最后:刷新一个页面看看效果吧,就写到这,( ^_^ )/~~拜拜

分类: 折腾北瓜 标签: , , ,

100%保证成功获取Akismet API KEY

2009年8月30日 IT北瓜 1 条评论

经过一番折腾(域名注册、空间购买、WP安装,这些就不在此唠叨啦),IT北瓜总算投入运作了。对于不懂PHP的来说,也只能磕磕撞撞、按部就班的来把这“瓜”给种起来,那么首先就从酋长老大的大作10件安装WordPress后需要做的事开始吧,好吧,唠叨了,进入主题。

很明显Akismet是本文的主角,也是10件事中的第一件。可是路途还真是坎坷啊+_+第一件事就碰钉子,Akismet是WordPress默认自带的反垃圾程序,启用该插件后提示需要一个Key来使其运作,

Akismet需要一个API KEY使其工作!

Akismet需要一个API KEY使其工作!

其实这倒也不是什么打不了的事,不就到WordPress官方网站注册一个帐号就可以轻而易举获得需要的Key吗?可是问题来了,但你满心欢喜的去点击那个“Sign up now”按钮的时候却发现给伟大的GFW了(+﹏+)~!当然认为知道“代理”为何物的你也跟一样不会就此放弃滴!!!

那么就该我们伟大的主角2号(这名份有点委屈仁兄您了,但主角1号给了Akismet,您就屈就一回吧,⊙﹏⊙,其伟大我想地球人都知道!)登场了,其尊姓大名这里就不明说了,GFW北瓜我还是很惧怕滴⊙﹏⊙,还等什么,赶紧下吧我就是主角2号

时光飞逝,岁月如梭…

下载完毕,OK,解压–>运行–>IE中打开WordPress官方网站–>Sign up now(一切风平浪静,畅通无阻)–>注册完毕收到激活邮件–>激活账号–>再次收到邮件(万事大吉,API Key已在邮件内容中)

接下来顺理成章、按部就班,本文到此结束,结果如下:

请输入一个API KEY!

请输入一个API KEY!

API KEY已经激活!

API KEY已经激活!