WordPress主题与文章类型相关

江河/ 2023年04月13日/ WordPress/ 浏览 739

对于新朋友而言,WordPress中的文章类型是令人迷糊的。


对于开发者来说,WordPress中的“文章”和面向对象编程中的“类”有点像。WordPress 中所有的文章都存储在 wp_posts 数据表中。wp_posts 有一个字段:post_type,文章类型说的就是这个字段。


post_type 默认的合规值有:


1. Post (Post Type: ‘post’)

2. Page (Post Type: ‘page’)

3. Attachment (Post Type: ‘attachment’)

4. Revision (Post Type: ‘revision’)

5. Navigation menu (Post Type: ‘nav_menu_item’)

6. Block templates (Post Type: ‘wp_template’)

7. Template parts (Post Type: ‘wp_template_part’)


除此之外,还有开发者自己注册的文章类型(使用 register_post_type 函数)。


对于建站者来说,“文章”一般特指特指 post_type 为 post 的文章。


搞清楚自己的角色是开发者还是建站者,就不会对 WordPress 中的文章迷糊了。


WordPress主题中对各种文章类型都有充分的支持。


文章类型 post 相关的模板文件包括:single.php、category.php、tag.php、taxonomy.php、archive.php、author.php、date.php、search.php、home.php、index.php 等。


文章类型 page 相关的模板文件包括:page.php、front-page.php、search.php、index.php 等。


文章类型 attachment 相关的模板文件包括:mimetype.php、attachment.php、single-attachment.php、single.php、index.php 等。


自定义文章类型的相关模板包括:single-{post-type}.php、archive-{post-type}.php、search.php、index.php 等。


对于 revision、nav_menu_item、wp_template、wp_template_part 四种类型,有点因为其不必展示,或是页面的一部分,而没有相对应的模板文件。


发表评论

暂无评论,抢个沙发...

客服 工单