---
title: "Typecho テーマ開発でよく使われるフック関数をいくつか紹介 - 憂いを忘れる一枚"
description: "Typecho を使っていた頃は、テーマやプラグインを自分でいろいろ試すことが多く、そのたびに docs.typecho.org でテーマやプラグインに関するよく使う関数を確認していました。"
canonical_url: "https://www.ikxin.com/ja/article/typecho-theme-functions"
last_updated: "2026-09-16T09:59:27.259Z"
locale: ja
meta:
  "og:description": "Typecho を使っていた頃は、テーマやプラグインを自分でいろいろ試すことが多く、そのたびに docs.typecho.org でテーマやプラグインに関するよく使う関数を確認していました。"
  "og:image": "https://www.ikxin.com/_og/d/h_630%2Ca_~VHlwZWNobyDjg4bjg7zjg57plovnmbrjgafjgojjgY~kvb~jgo~jgozjgovjg5Xjg4Pjgq~plqLmlbDjgpLjgYTjgY~jgaTjgYvntLnku4sgLSDmhoLjgYTjgpLlv5jjgozjgovkuIDmnpo%2Cc_Article%2Ctitle_~VHlwZWNobyDjg4bjg7zjg57plovnmbrjgafjgojjgY~kvb~jgo~jgozjgovjg5Xjg4Pjgq~plqLmlbDjgpLjgYTjgY~jgaTjgYvntLnku4s%2Cdescription_~VHlwZWNobyDjgpLkvb~jgaPjgabjgYTjgZ~poIPjga~jgIHjg4bjg7zjg57jgoTjg5fjg6njgrDjgqTjg7PjgpLoh6rliIbjgafjgYTjgo3jgYTjgo3oqabjgZnjgZPjgajjgYzlpJrjgY~jgIHjgZ3jga7jgZ~jgbPjgasgZG9jcy50eXBlY2hvLm9yZyDjgafjg4bjg7zjg57jgoTjg5fjg6njgrDjgqTjg7PjgavplqLjgZnjgovjgojjgY~kvb~jgYbplqLmlbDjgpLnorroqo3jgZfjgabjgYTjgb7jgZfjgZ~jgII%2CsiteName_~5oaC44GE44KS5b-Y44KM44KL5LiA5p6a%2CsiteHost_www.ikxin.com%2Cp_Ii9qYS9hcnRpY2xlL3R5cGVjaG8tdGhlbWUtZnVuY3Rpb25zIg%2Cs_7xUSV8aoZcRFggwy.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_~VHlwZWNobyDjg4bjg7zjg57plovnmbrjgafjgojjgY~kvb~jgo~jgozjgovjg5Xjg4Pjgq~plqLmlbDjgpLjgYTjgY~jgaTjgYvntLnku4sgLSDmhoLjgYTjgpLlv5jjgozjgovkuIDmnpo%2Cc_Article%2Ctitle_~VHlwZWNobyDjg4bjg7zjg57plovnmbrjgafjgojjgY~kvb~jgo~jgozjgovjg5Xjg4Pjgq~plqLmlbDjgpLjgYTjgY~jgaTjgYvntLnku4s%2Cdescription_~VHlwZWNobyDjgpLkvb~jgaPjgabjgYTjgZ~poIPjga~jgIHjg4bjg7zjg57jgoTjg5fjg6njgrDjgqTjg7PjgpLoh6rliIbjgafjgYTjgo3jgYTjgo3oqabjgZnjgZPjgajjgYzlpJrjgY~jgIHjgZ3jga7jgZ~jgbPjgasgZG9jcy50eXBlY2hvLm9yZyDjgafjg4bjg7zjg57jgoTjg5fjg6njgrDjgqTjg7PjgavplqLjgZnjgovjgojjgY~kvb~jgYbplqLmlbDjgpLnorroqo3jgZfjgabjgYTjgb7jgZfjgZ~jgII%2CsiteName_~5oaC44GE44KS5b-Y44KM44KL5LiA5p6a%2CsiteHost_www.ikxin.com%2Cp_Ii9qYS9hcnRpY2xlL3R5cGVjaG8tdGhlbWUtZnVuY3Rpb25zIg%2Cs_7xUSV8aoZcRFggwy.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,128  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; ?>
```

### 最新コメント一覧を取得する第 2 版。訪問者のコメントのみを表示し、ブログ管理者（つまり著者または自分自身）のコメントは表示しない

 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/ja#website","@type":"WebSite","description":"「憂いを忘れる一枚」は、技術探究と日々の暮らしをテーマにした個人サイトです。Web 開発、バックエンド、DevOps の実践を記録し、ソフトウェアツールやデジタル体験、コードの外で得た見聞と思索を共有します。","inLanguage":"ja-JP","name":"憂いを忘れる一枚","url":"https://www.ikxin.com/ja","translationOfWork":{"@id":"https://www.ikxin.com/#website"}},{"@id":"https://www.ikxin.com/ja/article/typecho-theme-functions#webpage","@type":"WebPage","description":"Typecho を使っていた頃は、テーマやプラグインを自分でいろいろ試すことが多く、そのたびに docs.typecho.org でテーマやプラグインに関するよく使う関数を確認していました。","name":"Typecho テーマ開発でよく使われるフック関数をいくつか紹介","url":"https://www.ikxin.com/ja/article/typecho-theme-functions","isPartOf":{"@id":"https://www.ikxin.com/ja#website"},"potentialAction":[{"@type":"ReadAction","target":["https://www.ikxin.com/ja/article/typecho-theme-functions"]}]}]}
```

## Sitemap

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