标签 typecho 下的文章

Typecho1.2.0文章内链接在新窗口打开

编辑模板文件function.php 添加parseContent()函数

function parseContent($obj){
    $options = Typecho_Widget::widget('Widget_Options');
    if(!empty($options->src_add) && !empty($options->cdn_add)){
        $obj->content = str_ireplace($options->src_add,$options->cdn_add,$obj->content);
    }
    $obj->content = preg_replace("/<a href=\"([^\"]*)\">/i", "<a href=\"\\1\" target=\"_blank\">", $obj->content);
    echo trim($obj->content);
}

该方法的原理就是正则文章的超链接标签,然后加上相应处理。
使用该方法需要修改模板post.php文件,将默认的内容输出<?php $this->content(); ?> 改成 <?php parseContent($this); ?>

Typecho全站https

1、编辑 config.inc.php 文件,增加一行

/** 开启HTTPS */
define('__TYPECHO_SECURE__',true);

2、后台设置中将http://www.2dan.cc 改成https://www.2dan.cc

3、数据库执行SQL语句

UPDATE `typecho_contents` SET TEXT = REPLACE( TEXT, 'http://www.2dan.cc/', 'https://www.2dan.cc/');

Typecho自定义首页描述Description内容

<?php if($this->is('index')): ?>
<?php $this->header('description=二蛋博客用来记录工作中遇到的问题和解决方法,并希望对遇到同样问题的人有所帮助,同时,当我需要再次重新设置的时候,能精确回忆起当初如何操作的。'); ?>
<?php else: ?>
<?php $this->header(); ?><?php endif; ?>

typecho在Nginx环境下的rewrite规则

location / {
    if (-f $request_filename/index.html){
        rewrite (.*) $1/index.html break;
    }
    if (-f $request_filename/index.php){
        rewrite (.*) $1/index.php;
    }
    if (!-f $request_filename){
        rewrite (.*) /index.php;
    }
}