# Typecho如何获取指定栏目下的文章

*Published:* 2024-01-01
*Author:* 客服001

#### 温馨提醒

如果文章内容或图片资源失效，请留言反馈，我们会及时处理，谢谢

本文最后更新于2024年1月1日，已超过 180天没有更新



typecho数据库里面，文章数据是单独一个表，而[栏目](https://www.xarjtc.com/tag/%e6%a0%8f%e7%9b%ae "查看栏目此标签更多文章")和文章id的关联又是一个表，所以单独输出某一个栏目下的文章内容，则需要在输出文章的时候进行联合查询（SQL 中 JOIN 子句用于把来自两个或多个表的行结合起来）

代码如下：

```
//直接在文章调用mou(分类id)
function mou($cid=NULL){
    if(empty($cid)){
        $cid = 1;
    }
    $db = <a class="tag_link" href="https://www.xarjtc.com/tag/typecho" target="_blank" title="查看Typecho此标签更多文章"><abbr title="">Typecho</abbr></a>_Db::get();
    $query = $db->select()
->from('table.contents')
->join('table.relationships', 'table.contents.cid = table.relationships.cid',Typecho_Db::INNER_JOIN)
->where('table.contents.type = ?', 'post')->where('table.relationships.mid = ?', $cid);
    
    $arr =  $db->fetchAll($query);
    return $arr;
    // print_r($arr) ;
}
```