首页 > Wordpress > WordPress建站笔记

WordPress建站笔记

2013年12月7日 发表评论 阅读评论

wordpress-logo

把不带www的域名重定向到带有www的域名中去:

本主机是win主机所以需要修改的是httpd.ini文件,添加:

RewriteCond Host: ^kylen314\.com$
RewriteRule (.*) http\://www\.kylen314\.com$1 [R,I]

去除每个页面URL中的index.php字样:

本主机是win主机所以需要修改的是httpd.ini文件,添加:

RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]

Mathematica语法高亮:

方法参见withparadox2大神的博客,需要下载google-code-prettify压缩包Mathematica Js压缩包两个压缩包,找到google-code-prettify\src\下面的prettify.js和Mathematica Js压缩包下的lang-mma.js和prettify-mma.css,传到自己服务器的某个路径下,大神方法是在主题的header.php中的之间加上调用代码:

<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/prettify/prettify-mma.css" type="text/css" media="screen, projection" />
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/prettify/prettify.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/prettify/lang-mma.js"></script>

然后再把…改成:

<body onload="prettyPrint()">...</body>

但是这样不管什么博文都要调用这个JS文件,所以我把这个删了,变成在需要的博文最后面加上这两行JS调用语句就可以了:

<script type="text/javascript" src="/wp-content/prettify/prettify.js"></script>
<script type="text/javascript" src="/wp-content/prettify/lang-mma.js"></script>

然后在需要调用Mathematica代码高亮的地方写上:

<pre class="prettyprint lang-mma">
...Your Code...
</pre>

CSS文件中的ul,ol,li属性

在改写自己主题的CSS文件的列表方式的时候,如果把list-style-position的值变成inside的话,那么还需要修改padding,不然的话前面的标记会不显示(其实是被盖掉了。。)

给博客添加favicon

首先可以到这里去创建一个16×16的ico文件,假设命名为favicon.ico,传到ftp的根目录下,再在主题header.php中添加:

<link rel="shortcut icon" href="<?php echo get_settings('home'); ?>/favicon.ico" type="image/x-icon" />

嫌麻烦的还可以直接用这个All-In-One-Favicon~

robots.txt

我的代码:

User-agent: *
Disallow: /wp-admin/
Disallow: /wp-includes/
Disallow: /wp-includes/
Disallow: /wp-
Disallow: /*/trackback
Disallow: /feed
Disallow: /*/feed
Disallow: /?s=*
Disallow: /*/?s=*
Disallow: /?r=*
Disallow: /?p=*
Disallow: /a/date/
Disallow: /a/author/
Disallow: /a/category/
Disallow: /?p=*&preview=true
Disallow: /?page_id=*&preview=true
Disallow: /wp-login.php
Disallow: /comments/feed
Sitemap: http://www.kylen314.com/sitemap.xml.gz
Sitemap: http://www.kylen314.com/sitemap_baidu.xml

URL重定向防止盗链

主机空间流量小的博客一般都要做一些防盗链措施,本机是win主机,所以需要修改的是httpd.ini文件,加上下面三行:

RewriteCond Host: (.+)
RewriteCond Referer: (?!http://(?:XXXX\.com|(.*)\.XXXX\.com|baidu\.com|(.*)\.baidu\.com|google\.com|(.*).\google.com)).*
RewriteRule .*\.(?:jpg|jpeg|gif|png|bmp|rar|zip|exe) /fangdao.gif [I,O,N]

百度站点地图

用了百度站点地图提交站点地图却找不到xml文件的方法: 在httpd.ini中添加:

RewriteRule /sitemap_baidu.xml /sitemap_baidu.xml [L]
RewriteRule /sitemap.html /sitemap.html [L]

修改滚动条样式

主题CSS文件中加入:

/*---滚动条默认显示样式--*/
.post ::-webkit-scrollbar-thumb{
  background-color:#018EE8;
  height:50px;
  -webkit-border-radius:4px;
}
/*---鼠标点击滚动条显示样式--*/
.post ::-webkit-scrollbar-thumb:hover{
  background-color:#FB4446;
  height:50px;
  -webkit-border-radius:4px;
}
/*---滚动条大小--*/
.post ::-webkit-scrollbar{
  width:8px;
  height:8px;
}
/*---滚动框背景样式--*/
.post ::-webkit-scrollbar-track-piece{
  background-color:#D3D3D3;
  -webkit-border-radius:5px;
}   

详情效果本文上面长代码处可以看得到。。

修改浏览器标签页中显示的文字

本站首页显示的是:网站标题|副标题 可以把主题header.php中<title>改成:

<title><?php bloginfo('name'); ?><?php wp_title(); ?>|<?php bloginfo('description'); ?></title>

添加回复验证码

functions.php中添加函数:

function spam_protection_math(){
	$num1=rand(0,9);
	$num2=rand(0,9);

	echo "<input type='text' name='sum' class='math_textfield' value='' size='28' tabindex='4'>
        验证码:$num1 + $num2 = ?"
	."<input type='hidden' name='num1' value='$num1'>"
	."<input type='hidden' name='num2' value='$num2'>";
	}
function spam_protection_pre($commentdata){
	$sum=$_POST['sum'];
	switch($sum){
		case $_POST['num1']+$_POST['num2']:break;
		case null:wp_die('错误: 请输入验证码.');break;
		default:wp_die('错误: 验证码错误,请重试.');
	}
	return $commentdata;
}
if($comment_data['comment_type']==''){
	add_filter('preprocess_comment','spam_protection_pre');
}

然后在Comment.php合适位置添加:

<div class="row"><?php spam_protection_math();?></div>

增强自带编辑器功能

functions.php中添加函数:

function enable_more_buttons($buttons) {

     $buttons[] = 'fontselect';
     $buttons[] = 'fontsizeselect';
     $buttons[] = 'styleselect';
     $buttons[] = 'backcolor';

     $buttons[] = 'wp_page';
     $buttons[] = 'anchor';

     $buttons[] = 'hr';
     $buttons[] = 'del';
     $buttons[] = 'sub';
     $buttons[] = 'sup';
     $buttons[] = 'cleanup';

     return $buttons;
     }
add_filter("mce_buttons_3", "enable_more_buttons");

每一篇post开始编辑时默认添加一些东西

functions.php中添加函数:

function insertPreContent($content) {
        if(!is_feed() && !is_home()) {
        $content.= "这里的预定义内容在编辑器可见";
        }
        return $content;
}
add_filter ('default_content', 'insertPreContent');

设置留言框提示语言

在Comment.php找到:

<textarea  name="comment" id="comment" tabindex="4" rows="8" cols="50"></textarea>

改成:

	<textarea style="color:gray"
                  onblur="if (this.value == '') {
                          this.value = '节操留言~';} "
                  onfocus="if (this.value == '节操留言~') {
                           this.value = '';}
        " name="comment" id="comment" tabindex="4" rows="8" cols="50">
         节操留言~
        </textarea>

文章首字母下沉

style.css中添加:

.post p:first-of-type:first-letter{
font-size: 48px;
padding: 10px;
float: left;
color:#2970A6;
}

编辑器添加自定义按钮

functions.php中添加函数:

function appthemes_add_quicktags() {
?>
 <script type="text/javascript">
 QTags.addButton( 'h1', 'h1', "<h1>", "</h1>\n" );
 </script>
<?php
}
add_action('admin_print_footer_scripts', 'appthemes_add_quicktags' );

设置默认编辑器为html

functions.php中添加函数:

add_filter( 'wp_default_editor', create_function('', 'return "html";') );

获取文章点击数

functions.php中添加函数:

function getPostViews($postID){      
    //字段名称      
    $count_key = 'post_views_count';      
    //获取字段值即浏览次数      
    $count = get_post_meta($postID, $count_key, true);      
    //如果为空设置为0      
    if($count==''){      
        delete_post_meta($postID, $count_key);      
        add_post_meta($postID, $count_key, '0');      
        return "0";      
    }      
    return $count;      
}      
//设置浏览数-参数文章ID      
function setPostViews($postID) {      
    //字段名称      
    $count_key = 'post_views_count';      
    //先获取获取字段值即浏览次数      
    $count = get_post_meta($postID, $count_key, true);      
    //如果为空就设为0      
    if($count==''){      
        $count = 0;      
        delete_post_meta($postID, $count_key);      
        add_post_meta($postID, $count_key, '0');      
    }else{      
        //如果不为空,加1,更新数据      
        $count++;      
        update_post_meta($postID, $count_key, $count);      
    }      
}    

然后再在single.phhp中< ?php get_header(); ?>下面添加:

<?php setPostViews(get_the_ID()); ?>

然后只要在你想要显示的地方添加:

 <?php echo getPostViews(get_the_ID()); ?>

【未完】

本文内容遵从CC版权协议,转载请注明出自http://www.kylen314.com

分类: Wordpress 标签: , ,
  1. 本文目前尚无任何评论.
验证码:8 + 9 = ?

友情提示:留言可以使用大部分html标签和属性;

添加代码示例:[code lang="cpp"]your code...[/code]

添加公式请用Latex代码,前后分别添加两个$$