WordPress 栏目

全球最流行的blog程序,本栏分享我的wordpress使用心得

谈谈wp的垃圾留言阻止

2009/04/06 | 作者:小V | 评论 (0)| 分类: WordPress

挺久没来看看,突然发现邮箱里有几百封未读,原来是wp的留言邮件提醒,一看会是E文的垃圾留言苦删半天。哎。

垃圾留言的阻止嘛,好像用插件过滤的人比较多。如:自带的Akismet、Spam Karma 2Comments For Cookies 等等。当然也有些麻烦就是了,主要也是些以过滤机器为主,一些人工留言的就没多大作用了。

我的空间本来就比较慢了,所以不打算用再用插件去做这些,想想还是算了用系统的spam关键字过滤。

这是我设置的关键字主要以过滤链接为主。

HREF="
herf="
</A>
</a>
.php?
.asp?
.jsp?
[url

当然还有些人工发的。内容没什么,但网址栏有些就留了危险无关的网址、关键字等。

commentspam

其实wp默认就在链接处加给那网址栏加了"nofollow"了,所以没什么关系。
如果再觉得不爽就再加个水煮鱼的url转向插件。效果就向我的留言。http://***/?R=你的url!
使用方法就向。。插件开启再给robot.txt加句Disallow: /?r=*。

WP增加似QQ个性签名记录(滔滔)效果

2009/02/17 | 作者:小V | 评论 (2)| 分类: WordPress

逛论坛的时候,发现有人问想要这种插件。我一想到插件就怕怕,觉得这种效果基本可以自已diy下就好。。 直接进主题。

我的思路是用一个page页然后把签名当做评论那样处理,而首页显示就利用最新评论那样来读取这个page页的你的评论。

当然这样看起来不是很好,有几个明显的缺点,别人乱回复评论怎么办,自已签名和别人评论混一起怎么办。。,其实也可以不用page页而是用一个新的分类然后再用文章来弄这样的效果,而最新评论当然也改成最新文章那样喽。

1.进系统后台增加一个page页,用默认单页模板就行,记得开留言。添加完可以从网址那里得到一个id。记下!

如:http://****/page.php?action=edit&post=176  要的就是最后面那个176!!,把它记下先。

2.找到你所用主题下有副标题的地方,或是你想放个性签名的地方,比如我的就是在页面最上面那个。。插入下面代码(最新评论用的)

<?php
global $comment;
if ( $comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID,comment_content, comment_post_ID FROM $wpdb->comments WHERE comment_approved='1' AND user_id='2' and comment_post_ID='245' ORDER BY comment_date_gmt DESC LIMIT 1") ) ;
foreach ($comments as $comment) {
echo '心情记录:' . sprintf('%2$s', get_comment_author_link(),'<a href="'. get_permalink($comment->comment_post_ID) .'#comment-' . $comment->comment_ID . '">' . get_comment_excerpt($comment->comment_post_ID) . '</a>');
}
?>

3.更改上面那个sql语句

SELECT comment_author, comment_author_url, comment_ID,comment_content, comment_post_ID FROM $wpdb->comments WHERE comment_approved='1' AND user_id='2'

(这边的那个2表示你后台用户的id默认是1,访客是0,我的是2.)

and comment_post_ID='245'(这里的245就是刚才第一步添加page页后记下来的id如把它再改成176) ORDER BY comment_date_gmt DESC LIMIT 1

只是简单的改一下数值而已。。

完后自已测试吧。也可以看我的效果:http://vl99.com/最上面那行。。。

分类的比这个简单,不说了。。

WP新增自定义单页模板页及wp_list_pages()

2009/02/06 | 作者:小V | 评论 (0)| 分类: WordPress

  用Wp两个月,到现在才发现这问题。最近比较忙没时间研究东西,一遇上麻烦连问题应该怎么问都想不到,摸索良久终搞定问题,记下来免得忘记了。 

 本想把存档页的div切换给换掉。切换后要求内容用网址调用,需要单独页面必须新建一页,但随便建php并不能直接让wp的函数运行。应该先在模板目录下建一下你要的*.php,并在这个*.php里面加入

<?php
/*
Template Name: 模板名字
*/
?>

 再进后台新建一个调用此模板的新页面。就能得到这页面的url了并能自定义各自的php代码。

当然有些时候只是做程序调用的。不想让新建的那模板而显示在导航里,就要改一下wp_list_pages()了

 比如导航一般模板里会写

<?php wp_list_pages('title_li=); ?>

在后台把想隐藏的页面弄为2级,再改成

<?php wp_list_pages('title_li=&depth=1' ); ?>

 

相关的函数还有

depth:深度。页面可以建N级的,你可以调用一层,也可以调用N层。
show_date:创建日期。这里可以设置是不是显示创建的日期。
date_format:如果你设置显示日期,你可以在这里设置限制的格式,无非就是那个y了d了啥的。
child_of:这里设置是不是显示子页面。
exclude:设置显示哪些页面,根据页面设置的代码。
title_li:这里设置显示不显示标题,就像侧栏那里日志分类上面有个h2包起来的“日志分类”一样。
echo:有两个值,1和0,1就显示页面链接,2就不显示。
authors:wp里面这个很多了,就是显示不显示作者了。
sort_columu:这个下面好像内容很多,是设置根据啥排序的。默认的是根据”post_title”,还有”menu_order”;”post_date”;”ID”等等。

wp的导航栏定位方法

2009/01/04 | 作者:小V | 评论 (1)| 分类: WordPress

今天觉得自已blog的模板不太好看..  其实想了很久想改,一直都没动手..

随便弄了一下.就遇到个导航栏标签定位的问题, 本想用css加在bodyid或js判断直接弄.后来发现原来还可以这样.. wp挺不错的.呵

wp原来的就有支持这个. 不过他的css是用在li里面.我要的是椭圆的按钮所以要放在span里面.. 如下面的出来的效果和css:

可以看出原来它的样式是为<li class="page_item page-item-2 current_page_item">而定位后的聚焦为current_page_item.

这是出来的html:

<div id="menu_items">
<ul>
<li><a href="http://***.com/wp/" class=""><span>首页</span></a></li>
<li class="page_item page-item-2 current_page_item"><a class="page_item page-item-2 current_page_item" href="http://***.com/wp/about" title="About"><span>About</span></a></li>
<li class="page_item page-item-45"><a class="page_item page-item-45" href="http://***.com/wp/guestbook" title="Guestbook"><span>Guestbook</span></a></li>
</ul>
<div class="clear"></div>
</div>

这是我的css....

#menu_items{
float:left;
margin-left:20px;
}

#menu_items ul{
list-style:none;

}
#menu_items li{
list-style:none;
display:block;
float:left;
}
#menu_items li a{
display:block;
float:left;
height:43px;
color:#fff;
text-transform:uppercase;
font-size:11px;
font-weight:bold;
background:url(images/menu_007_left.jpg) no-repeat left;
line-height:43px;
padding:0 0 0 7px;
text-decoration:none;
}
#menu_items li a span{
display:block;
float:left;
background:url(images/menu_007_right.jpg) no-repeat right;
height:43px;
color:#fff;
line-height:43px;
padding:0 14px 0 6px;
cursor:pointer;
}
#menu_items li a:hover{
display:block;
float:left;
background:url(images/menu_007_left_h.jpg) no-repeat left;
height:43px;
}
#menu_items li a:hover span{
display:block;
float:left;
background:url(images/menu_007_right_h.jpg) no-repeat right;
color:#fff;
height:43px;
}
#menu_items li a.current_page_item{
display:block;
float:left;
height:43px;
color:#fff;
text-transform:uppercase;
font-size:11px;
font-weight:bold;
background:url(images/menu_007_left_h.jpg) no-repeat left;
line-height:43px;
padding:0 0 0 7px;
text-decoration:none;
}
#menu_items li a.current_page_item span{
display:block;
float:left;
background:url(images/menu_007_right_h.jpg) no-repeat right;
height:43px;
color:#fff;
line-height:43px;
padding:0 14px 0 6px;
}

呵呵..其实这里才是开始看的东西... 晕

修改方法给首页弄一个

class="<?php if( is_home() ) { ?> current_page_item<?php } ?>

加在链接里面.判断当前是否为主页而聚焦...找不到一个好的词不好意思

而页面列表wp里面就有函数了.直接用

<?php wp_list_pages('title_li=');?>

这是我的代码:

<div id="menu_items">
<ul>
<li><a href="<?php echo get_option('home'); ?>/" class="<?php if( is_home() ) { ?> current_page_item<?php } ?>"><span>首页</span></a></li>
<?php wp_list_pages('title_li=');?>
</ul>

如果你对你的导航栏还有别的要求,比如css应该加在span或a里面 .

你就在wp-includesclasses.php里找到下面这段代码来更改

function start_el(&$output, $page, $depth, $args, $current_page) {
if ( $depth )
$indent = str_repeat("t", $depth);
else
$indent = '';

extract($args, EXTR_SKIP);
$css_class = 'page_item page-item-'.$page->ID;
if ( !empty($current_page) ) {
$_current_page = get_page( $current_page );
if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) )
$css_class .= ' current_page_ancestor';
if ( $page->ID == $current_page )
$css_class .= ' current_page_item';
elseif ( $_current_page && $page->ID == $_current_page->post_parent )
$css_class .= ' current_page_parent';
} elseif ( $page->ID == get_option('page_for_posts') ) {
$css_class .= ' current_page_parent';
}

$output .= $indent . '<li class="' . $css_class . '"><a class="' . $css_class . '" href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '"><span>' . $link_before . apply_filters('the_title', $page->post_title) . $link_after . '</span></a>';

if ( !empty($show_date) ) {
if ( 'modified' == $show_date )
$time = $page->post_modified;
else
$time = $page->post_date;

$output .= " " . mysql2date($date_format, $time);
}
}

我只在这里为我的a放上个class就好了..

$output .= $indent . '<li class="' . $css_class . '"><a class="' . $css_class . '" href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '"><span>' . $link_before . apply_filters('the_title', $page->post_title) . $link_after . '</span></a>';
Page 4 of 41234
Page 4 of 41234