typecho标签灵活运用

<?php $this->widget('Widget_Archive@digest', 'pageSize=5&type=tag','mid=41')->to($digest); ?>
...
<?php while($digest->next()): ?>
...
<a href="<?php $digest->permalink() ?>"><?php $digest->title() ?></a>
...
<?php endwhile; ?>

typecho的tag跟分类归属一个表,在不适合设置太多分类的情况下,给文章设置一个固定tag,然后指定tag可以各种调用,置顶,专项,集合什么的

Typecho 1.1 如何嵌入 HTML 标签

更新1.1之后,typecho更换了md编辑器,html的标签都会直接显示为文本了
那就用!!!来显示html内容
内容如下:

!!!
<center>居中</center>
!!!
  1. 加了

    居中
  2. 未加
    居中

???
又被骗了

typecho一些代码片段

前台删除文章确认

    //post-meta-more
    $(document).ready(function() {
        $(document).on('click','.post-meta-more b', function () {
            var thiz = $(this).parent();
            $('.post-meta-more').not(thiz).removeClass('show');
            thiz.toggleClass('show');
        });
        $(document).on('click',function(event){
            if(!$(event.target).closest('.post-meta-more').length){
                $('.post-meta-more').removeClass('show');
            }
        })
        $('article').fadeIn();
    });
    //前台删除文章确认
    $('.delete').click(function () {
        if (confirm('<?php _e('您确认要删除吗?'); ?>')) {
            window.location.href = $(this).attr('href');
        }

        return false;
    });

随机调用文章

class Rande extends Widget_Abstract_Contents
{
    /**
     * 随机调用文章
     */
    public function execute()
    {
        $this->parameter->setDefault(['pageSize' => $this->options->postsListSize]);

        $this->db->fetchAll($this->select()
            ->from('table.contents')
            ->join('table.relationships', 'table.contents.cid = table.relationships.cid')
            ->where('table.contents.type = ?', 'post')->where('table.relationships.mid = ?', $this->parameter->mid)
            ->where('table.contents.status = ?', 'publish')
            ->where('table.contents.created < ?', $this->options->time)
            ->where('table.contents.type = ?', 'post')
            ->order($this->parameter->order?$this->parameter->order:'table.contents.created', Typecho_Db::SORT_DESC)
            ->limit($this->parameter->pageSize), [$this, 'push']);
    }
}
<?php $this->widget('Rande@Rande', 'pageSize=10&mid=7&order=rand()')->to($rand); ?>

根据分类slug调用mid

根据源码内容,获取当前页面的mid有更方便的方式
$this->getPageRow()['mid']
下面的方式可以用于非当前页面,暂时还没想到用在哪里,先放着吧
function cmid($slug){  //根据栏目slug获取栏目id,cmid($this->getArchiveSlug())
    $db = Typecho\Db::get();
    $cmid = $db->fetchRow($db->select()->from ('table.metas')->where ('slug=?',$slug)->where('type=?', 'category'));
    return  $cmid['mid']; 
 }
//使用方法
<?php cmid($this->getArchiveSlug())?>
<?php cmid($slug)?>

分类指定模板方法

网上部分内容不太合适

<?php
    $slugArray = array('game','loneone','web','observer','lifes');
    if(in_array($this->getArchiveSlug(),$slugArray)){
        $this->need('category-life.php');
    }else {
        $this->need('archive-default.php');
    }
?>

横向放的就是因为transform导致z-index不起作用的

扫一扫,访问移动端

高凯的个人主页
I am alone on my life's Journey up to now, and the future.

推荐 / Digest

热点 / Hot

评论 / Comments

  • Gaobukai: 这还发现一个bug,不能自动换行了
  • Gaobukai: 图片挂了就挂了把
  • Gaobukai: 新款的修改方式:124行增加 /** 用户注册时间...
  • Gaobukai: <img class="profile-avat...
  • nico: 头像改为以下函数,还是不起作用。src="<?php av...
  • nico: 现在主题是用下面代码实现src="<?php tx($ne...

标签 / Tags

推广 / Ads