文章缩略图

function showThumb($obj,$size=null,$link=false){
    preg_match_all( "/<[img|IMG].*?src=[\'|\"](.*?)[\'|\"].*?[\/]?>/", $obj->content, $matches );
    $thumb = '';
    $options = Typecho_Widget::widget('Widget_Options');
    $attach = $obj->attachments(1)->attachment;
    if (isset($attach->isImage) && $attach->isImage == 1){
        $thumb = $attach->url;
        if(!empty($options->src_add) && !empty($options->cdn_add)){
            $thumb = str_ireplace($options->src_add,$options->cdn_add,$thumb);
        }
    }elseif(isset($matches[1][0])){
        $thumb = $matches[1][0];
        if(!empty($options->src_add) && !empty($options->cdn_add)){
            $thumb = str_ireplace($options->src_add,$options->cdn_add,$thumb);
        }
    }
    if(empty($thumb) && empty($options->default_thumb)){
        return '';
    }else{
        $thumb = empty($thumb) ? $options->default_thumb : $thumb;
    }
    if($link){
        return $thumb;
    }
}

调用代码

<?php $thumb = showThumb($this,null,true);?>
<?php if(!empty($thumb)):?>
<?php echo $thumb;?>
<?php else : ?>
没有图片
<?php endif; ?>

各种判断语句

<?php if($this->is('index')):?>
首页
<?php if($this->is('category')):?>
分类
<?php if($this->is('category', 'category1')):?>
独立分类
<?php if($this->category == "help"): ?>
首页判断文章所在分类
<?php if($this->is('page')):?>
页面
<?php if($this->is('page', 'page1')):?>
独立页面
<?php if($this->is('post')):?>
内容页
<?php if ($pages->slug != 'page1'): ?>
导航不显示某页面
<?php if (($pages->slug != 'page1') && ($pages->slug != 'page2')): ?>
导航不显示某两个页面
<?php if ($category->slug != 'category1'): ?>
导航不显示某分类
<?php if (($category->slug != 'category1') && ($pages->slug != 'category2')): ?>
导航不显示两个分类
<?php if($this->category != "category1"): ?>
首页不显示某分类
<?php if (($this->_currentPage == 1) && ($this->sequence == 1)): ?>
首页第一篇文章
<?php elseif (array_key_exists('字段值',unserialize($this->___fields()))): ?>
自定义字段
<?php if($this->user->hasLogin()): ?>
是否登录
<?php endif; ?>