WordPress 主题开发中，很多时间需要在文章与列表中进行判断从而输出不同的内容，比如文章分类，只想在列表中显示，文章中不显示。列表页面可直接使用`is_archive()`来判断，或者直接排除不是文章页的所有页面，可以使用`!is_single()`。如果列表在文章中，比如相关文章，这样就不好判断，这时可以使用`in_the_loop()`来判断内容是不是在循环中，从而做到列表与文章页面中的内容不一样。

### 一、描述

判断内容是否在循环中（即循环当前是否为激活状态）

### 二、使用

```
in_the_loop();
```

### 三、参数

无

### 四、使用

向文章循环中的标题与内容前添加内容，将以下代码添加到函数文件 functions.php 中。

```
add_filter( 'the_title', 'modify_single_post_entry_titles' );
function modify_single_post_entry_titles( $title ) {
	if ( is_singular( 'post' ) && in_the_loop() ) {
		/* Modify $title */
	}
	return $title;
}
```

在循环中进行判断的方法：

```
if (in_the_loop()) {
    echo '内容';
}
```

如果以上代码处于循环中，将输出『内容』。

### 五、返回值

如果调用的内容在循环中，则为True;如果循环没有启动或已经结束，则为false。