---
title: "Typecho 테마 개발 과정에서 자주 사용하는 훅 함수 공유 - 근심을 잊는 한 장"
description: "以前还在使用 Typecho 的时候，我经常自己折腾主题插件，因此也常常需要前往 docs.typecho.org 查看主题插件相关的常用函数。"
canonical_url: "https://www.ikxin.com/ko/article/typecho-theme-functions"
last_updated: "2026-09-16T09:59:27.259Z"
locale: ko
meta:
  "og:description": "以前还在使用 Typecho 的时候，我经常自己折腾主题插件，因此也常常需要前往 docs.typecho.org 查看主题插件相关的常用函数。"
  "og:image": "https://www.ikxin.com/_og/d/h_630%2Ca_~VHlwZWNobyDthYzrp4gg6rCc67CcIOqzvOygleyXkOyEnCDsnpDso7wg7IKs7Jqp7ZWY64qUIO2bhSDtlajsiJgg6rO17JygIC0g6re87Ius7J2EIOyeiuuKlCDtlZwg7J6l%2Cc_Article%2Ctitle_~VHlwZWNobyDthYzrp4gg6rCc67CcIOqzvOygleyXkOyEnCDsnpDso7wg7IKs7Jqp7ZWY64qUIO2bhSDtlajsiJgg6rO17Jyg%2Cdescription_~5Lul5YmN6L-Y5Zyo5L2~55SoIFR5cGVjaG8g55qE5pe25YCZ77yM5oiR57uP5bi46Ieq5bex5oqY6IW-5Li76aKY5o-S5Lu277yM5Zug5q2k5Lmf5bi45bi46ZyA6KaB5YmN5b6AIGRvY3MudHlwZWNoby5vcmcg5p-l55yL5Li76aKY5o-S5Lu255u45YWz55qE5bi455So5Ye95pWw44CC%2CsiteName_~6re87Ius7J2EIOyeiuuKlCDtlZwg7J6l%2CsiteHost_www.ikxin.com%2Cp_Ii9rby9hcnRpY2xlL3R5cGVjaG8tdGhlbWUtZnVuY3Rpb25zIg%2Cs_wQhrCd7ITDzB-W0S.png"
  "og:image:alt": "Typecho 테마 개발 과정에서 자주 사용하는 훅 함수 공유 - 근심을 잊는 한 장"
  "og:image:height": "630"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Typecho 테마 개발 과정에서 자주 사용하는 훅 함수 공유"
  "twitter:image": "https://www.ikxin.com/_og/d/h_630%2Ca_~VHlwZWNobyDthYzrp4gg6rCc67CcIOqzvOygleyXkOyEnCDsnpDso7wg7IKs7Jqp7ZWY64qUIO2bhSDtlajsiJgg6rO17JygIC0g6re87Ius7J2EIOyeiuuKlCDtlZwg7J6l%2Cc_Article%2Ctitle_~VHlwZWNobyDthYzrp4gg6rCc67CcIOqzvOygleyXkOyEnCDsnpDso7wg7IKs7Jqp7ZWY64qUIO2bhSDtlajsiJgg6rO17Jyg%2Cdescription_~5Lul5YmN6L-Y5Zyo5L2~55SoIFR5cGVjaG8g55qE5pe25YCZ77yM5oiR57uP5bi46Ieq5bex5oqY6IW-5Li76aKY5o-S5Lu277yM5Zug5q2k5Lmf5bi45bi46ZyA6KaB5YmN5b6AIGRvY3MudHlwZWNoby5vcmcg5p-l55yL5Li76aKY5o-S5Lu255u45YWz55qE5bi455So5Ye95pWw44CC%2CsiteName_~6re87Ius7J2EIOyeiuuKlCDtlZwg7J6l%2CsiteHost_www.ikxin.com%2Cp_Ii9rby9hcnRpY2xlL3R5cGVjaG8tdGhlbWUtZnVuY3Rpb25zIg%2Cs_wQhrCd7ITDzB-W0S.png"
  "twitter:image:alt": "Typecho 테마 개발 과정에서 자주 사용하는 훅 함수 공유 - 근심을 잊는 한 장"
---

> Index of every page on this site: [llms.txt](https://www.ikxin.com/llms.txt)

# **Typecho 테마 개발 과정에서 자주 사용하는 훅 함수 공유**

2017.07.31 58,129  1

以前还在使用 Typecho 的时候，我经常自己折腾主题插件，因此也常常需要前往 [docs.typecho.org](https://docs.typecho.org) 查看主题插件相关的常用函数。

为了方便更多开发者和初学者更好、更快捷地学习制作 Typecho 主题，我整理了一些经常使用的函数，分享给大家使用！

![图片](https://www.ikxin.com/_ipx/animated_true&w_1734&f_webp/https://img.8b5.cn/2019/06/25/5d11adf707b49.jpg)

### 사이트 이름

 Plain Text

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

### 사이트 URL

 Plain Text

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

### 전체 경로 제목

 Plain Text

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

### 사이트 설명

 Plain Text

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

### 템플릿 폴더 주소

 Plain Text

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

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

 Plain Text

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

### 글 또는 페이지 작성자

 Plain Text

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

### 작성자 아바타

 Plain Text

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

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

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

 Plain Text

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

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

 Plain Text

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

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

 Plain Text

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

### 이전 글과 다음 글 호출 코드

 Plain Text

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

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

 Plain Text

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

`// 首页输出内容`

 Plain Text

```
<?php else: ?>
```

`// 不是首页输出内容`

 Plain Text

```
<?php endif; ?>
```

### 글 또는 페이지의 댓글 수

 Plain Text

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

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

 Plain Text

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

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

### 사용자 정의 필드 호출

 Plain Text

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

### RSS 주소

### 최신 post 가져오기

 Plain Text

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

### 링크가 없는 일반 텍스트 분류 이름

 Plain Text

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

### 글 분류 목록 가져오기

 Plain Text

```
<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 가져오기

 Plain Text

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

### 최신 댓글 목록 가져오기

 Plain Text

```
<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>
```

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

 Plain Text

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

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

 Plain Text

```
<?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; ?>
```

### 글 날짜 아카이브 가져오기

 Plain Text

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

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

 Plain Text

```
<?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; ?>
```

### 해당 글의 관련 글 목록 호출

 Plain Text

```
<?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 영역의 프로그램 버전과 템플릿 이름 숨기기

 Plain Text

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

### 독자 명예의 전당 가져오기

 Plain Text

```
<?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;?>
```

### 로그인 사용자와 비로그인 사용자에게 서로 다른 내용 표시

 Plain Text

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

로그인 사용자에게 표시

 Plain Text

```
<?php else: ?>
```

비로그인 사용자와 로그인 사용자 모두에게 표시

 Plain Text

```
<?php endif; ?>
```

## **댓글**

(1)

1. [**zizdog**](http://zizdog.com)2020. 12. 05. 16:34 Firefox 83 Windows 10

   重返独立博客，写板子，查文章，谢谢分享。

## **댓글 작성**

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://www.ikxin.com/ko#website","@type":"WebSite","description":"근심을 잊는 한 장은 기술 탐구와 일상을 다루는 개인 웹사이트입니다. 웹 개발, 백엔드 및 DevOps 실무를 기록하고 소프트웨어 도구와 디지털 경험, 코드 밖의 견문과 생각을 나눕니다.","inLanguage":"ko-KR","name":"근심을 잊는 한 장","url":"https://www.ikxin.com/ko","translationOfWork":{"@id":"https://www.ikxin.com/#website"}},{"@id":"https://www.ikxin.com/ko/article/typecho-theme-functions#webpage","@type":"WebPage","description":"以前还在使用 Typecho 的时候，我经常自己折腾主题插件，因此也常常需要前往 docs.typecho.org 查看主题插件相关的常用函数。","name":"Typecho 테마 개발 과정에서 자주 사용하는 훅 함수 공유","url":"https://www.ikxin.com/ko/article/typecho-theme-functions","isPartOf":{"@id":"https://www.ikxin.com/ko#website"},"potentialAction":[{"@type":"ReadAction","target":["https://www.ikxin.com/ko/article/typecho-theme-functions"]}]}]}
```

## Sitemap

See the full [sitemap](https://www.ikxin.com/sitemap.md) for all pages.
