예전에 Typecho를 사용하던 시절, 테마 플러그인을 직접 이것저것 수정하곤 했고, 그때마다 테마 플러그인에 관한 자주 사용하는 함수를 확인하기 위해 docs.typecho.org에 자주 방문해야 했습니다.

더 많은 개발자와 초보자가 Typecho 테마 제작을 더 쉽고 빠르게 배울 수 있도록, 자주 사용되는 함수들을 정리하여 여러분과 공유합니다!

이미지

사이트 이름

<?php $this->options->title() ?>

사이트 URL

<?php $this->options->siteUrl(); ?>

전체 경로 제목

<?php $this->archiveTitle(' &raquo; ', '', ' | '); ?><?php $this->options->title(); ?>

사이트 설명

<?php $this->options->description() ?>

템플릿 폴더 주소

<?php $this->options->themeUrl(); ?>

템플릿 폴더 내 PHP 파일 불러오기

<?php $this->need('.php'); ?>

글 또는 페이지의 작성자

<?php $this->author(); ?>

작성자 아바타

<?php $this->author->gravatar('40') ?>

여기서는 완전한 img 태그가 출력되며, 40은 아바타의 너비와 높이입니다.

해당 글 작성자의 모든 글 목록 링크

<?php $this->author->permalink (); ?>

해당 글 작성자의 개인 홈페이지 링크

<?php $this->author->url(); ?>

해당 글 작성자의 이메일 주소

<?php $this->author->mail(); ?>

이전 글과 다음 글 호출 코드

<?php $this->thePrev(); ?>
<?php $this->theNext(); ?>

홈페이지인지 판단하여 관련 내용 출력

<?php if ($this->is('index')): ?>

// 首页输出内容

<?php else: ?>

// 不是首页输出内容

<?php endif; ?>

글 또는 페이지의 댓글 수

<?php $this->commentsNum('No Comments', '1 Comment', '%d Comments'); ?>

글 일부 잘라내기 (홈페이지에서 각 글의 요약 표시)

<?php $this->excerpt(200, '...'); ?>

200은 잘라낼 글자 수입니다.

사용자 정의 필드 호출

<?php $this->fields->fieldName ?>

RSS 주소

최신 post 가져오기

<?php $this->widget('Widget_Contents_Post_Recent', 'pageSize=8&type=category')->parse('<li><a href="{permalink}">{title}</a></li>'); ?>

링크가 없는 순수 텍스트 분류 이름

<?php $this->category(',', false); ?>

글 분류 목록 가져오기

<ul>
<?php 
$this->widget('Widget_Archive@indexyc', 'pageSize=8&type=category', 'mid=1')
->parse('<li><a href="{permalink}" title="{title}">{title}</a></li>'); ?>
</ul>

특정 분류의 post 가져오기

<ul>
<?php 
$this->widget('Widget_Archive@indexyc', 'pageSize=8&type=category', 'mid=1')
->parse('<li><a href="{permalink}" title="{title}">{title}</a></li>'); ?>
</ul>

최신 댓글 목록 가져오기

<ul>
    <?php $this->widget('Widget_Comments_Recent')->to($comments); ?>
    <?php while($comments->next()): ?>
        <li><a href="<?php $comments->permalink(); ?>">
        <?php $comments->author(false); ?></a>:
        <?php $comments->excerpt(50, '...'); ?></li>
    <?php endwhile; ?>
</ul>

홈페이지에서 최신 글의 표시 개수 제한

<?php while ($this->next()): ?>
<?php if ($this->sequence <= 3): ?>
html
<?php endif; ?>
<?php endwhile; ?>

최신 댓글 목록 가져오기 두 번째 버전, 방문자 댓글만 표시하고 블로거(즉 작성자 또는 본인이 작성한 댓글)는 표시하지 않기

<?php $this->widget('Widget_Comments_Recent','ignoreAuthor=true')->to($comments); ?>
    <?php while($comments->next()): ?>
    <li><a href="<?php $comments->permalink(); ?>">
    <?php $comments->author(false); ?></a>:
    <?php $comments->excerpt(50, '...'); ?></li>
<?php endwhile; ?>

글 날짜 아카이브 가져오기

<ul>
    <?php $this->widget('Widget_Contents_Post_Date', 'type=month&format=F Y')
                ->parse('<li><a href="{permalink}">{date}</a></li>'); ?>
</ul>

태그 모음, 즉 태그 클라우드 가져오기

<?php $this->widget('Widget_Metas_Tag_Cloud', 'ignoreZeroCount=1&limit=28')->to($tags); ?>
<?php while($tags->next()): ?>
<a href="<?php $tags->permalink(); ?>" class="size-<?php $tags->split(5, 10, 20, 30); ?>"><?php $tags->name(); ?></a>
<?php endwhile; ?>

해당 글의 관련 글 목록 호출

<?php $this->related(5)->to($relatedPosts); ?>
    <?php if ($relatedPosts->have()): ?>
    <?php while ($relatedPosts->next()): ?>
        <li><a href="<?php $relatedPosts->permalink(); ?>" title="<?php $relatedPosts->title(); ?>"><?php $relatedPosts->title(); ?></a></li>
    <?php endwhile; ?>
    <?php else : ?>
        <li>无相关文章</li>
    <?php endif; ?>

head 영역의 프로그램 버전 및 템플릿 이름 숨기기

<?php $this->header("generator=&template="); ?>

독자 월 가져오기

<?php
$period = time() - 999592000; // 时段: 30 天, 单位: 秒
$counts = Typecho_Db::get()->fetchAll(Typecho_Db::get()
->select('COUNT(author) AS cnt','author', 'url', 'mail')
->from('table.comments')
->where('created > ?', $period )
->where('status = ?', 'approved')
->where('type = ?', 'comment')
->where('authorId = ?', '0')
->group('author')
->order('cnt', Typecho_Db::SORT_DESC)
->limit(25)
);
$mostactive = '';
$avatar_path = 'http://www.gravatar.com/avatar/';
foreach ($counts as $count) {
  $avatar = $avatar_path . md5(strtolower($count['mail'])) . '.jpg';
  $c_url = $count['url']; if ( !$c_url ) $c_url = Helper::options()->siteUrl;
  $mostactive .= "<a href='" . $c_url . "' title='" . $count['author'] . " (参与" . $count['cnt'] . "次互动)' target='_blank'><img src='" . $avatar . "' alt='" . $count['author'] . "的头像' class='avatar' width='32' height='32' /></a>\n";
}
echo $mostactive;
?>

로그인 여부에 따라 다른 내용 표시

<?php if($this->user->hasLogin()): ?>

로그인한 사용자에게만 표시

<?php else: ?>

로그인 여부와 관계없이 표시

<?php endif; ?>