Typecho 永久链接 设置伪静态

Typecho Apache 环境下伪静态规则,保存在网站根目录 .htaccess 文件中

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Typecho Nginx 环境伪静态规则,保存在 nginx.conf 配置文件中

if (!-e $request_filename) {
    rewrite ^(.*)$ /index.php$1 last;
}

未整理

typecho缩略图

主题直接提取缩略图代码

index.php

<?php
preg_match_all("/\<img.*?src\=(\'|\")(.*?)(\'|\")[^>]*>/i", $this->content, $matches);
$imgCount = count($matches[0]);
if($imgCount >= 1){
    $img = $matches[2][0];
echo <<<Html

 <a href="{$this->permalink}" title="{$this->title}" class="tu"><img src="{$img}?x-oss-process=style/szd2"  alt="{$this->title}" /></a>

Html;
}
?>

yijile2015模版所使用

index.php

<?php echo img_postthumb($this->cid); ?>

functions.php


/**
 * 输出文章缩略图
 *
 * @author ShingChi
 * @access public
 * @param int $width 缩略图宽度
 * @param int $height 缩略图高度
 * @return viod
 * @version Release 1.0.4
 */
function img_postthumb($cid) {
    $db = Typecho_Db::get();
    $rs = $db->fetchRow($db->select('table.contents.text')
        ->from('table.contents')
        ->where('table.contents.cid=?', $cid)
        ->order('table.contents.cid', Typecho_Db::SORT_ASC)
        ->limit(1));

    preg_match_all('/((http|https):\/\/)[0-9a-z\.\/]+(\.(jpg|jpeg|png|gif))/i', $rs['text'], $thumbUrl);
    //会错误获取一切网址 /http:\/\/[0-9a-z\.\/]+[.jpg|.png|.gif]/i
    //preg_match_all("/\<img.*?src\=\"(.*?)\"[^>]*>/i", $rs['text'], $thumbUrl);  //通过正则式获取图片地址
    $img_src = $thumbUrl[0][0];  //将赋值给img_src
    $img_counter = count($thumbUrl[0]);  //一个src地址的计数器

    switch ($img_counter > 0) {
        case $allPics = 1:
            echo '<span class="SpanPic"><img src="./plus/timthumb.php?zc=1&h=130&w=200&src=';
            echo $img_src;  //当找到一个src地址的时候,输出缩略图
            echo '" alt="缩略图"></span>';
            break;
        default:
            echo ""; //没找到(默认情况下),不输出任何内容 echo(rand(1,3));  echo "http://placekitten.com/42";echo(rand(0,9));echo "/19";echo(rand(0,9));
    };
}

/**
 * 输出文章缩略图
 *
 * @author ShingChi
 * @access public
 * @param int $width 缩略图宽度
 * @param int $height 缩略图高度
 * @return viod
 * @version Release 1.0.4
 */
function img_cover($cid) {
    $db = Typecho_Db::get();
    $rs = $db->fetchRow($db->select('table.contents.text')
        ->from('table.contents')
        ->where('table.contents.cid=?', $cid)
        ->order('table.contents.cid', Typecho_Db::SORT_ASC)
        ->limit(1));
    preg_match_all('/((http|https):\/\/)[0-9a-z\.\/]+(\.(jpg|jpeg|png|gif))/i', $rs['text'], $thumbUrl);
    $img_src = $thumbUrl[0][0];
    $img_counter = count($thumbUrl[0]);

    switch ($img_counter > 0) {
        case $allPics = 1:
            echo $img_src;
            break;
        default:
            echo ""; //没找到(默认情况下),不输出任何内容 echo(rand(1,3));  echo "http://placekitten.com/42";echo(rand(0,9));echo "/19";echo(rand(0,9));
    };
}

typecho相关教程

旧收藏文章


回到顶部

Copyright © 2017-2024 1px.run (像素教程) Distributed by an MIT license.

Site updated at 2024-04-23 12:45