WordPress post_class() 函数

post_class 是 WordPress 内置的一个用于显示文章 class 名称的函数,该函数通常会为每一篇文章生成独一无二的 class 值,如果你需要制作你自己的主题,而且还需要一点个性的话,那你最好驻足一下,使用该函数并配合灵活的 css 代码,我们可以制作出个性化十足的 WordPress 博客。

post_class 函数描述

该函数通常会为每一篇文章生成独一无二的 class 值,可以很方便使用于文章所在的节点中。

函数使用

向其他的诸如 header_image、wp_title这样的 WordPress 标签函数一样,不带 get 的函数通常是会直接显示出来而不返回任何值。

<post id="post-<?php the_ID();?>" <?php post_class();?> > <?php the_content ;?> </post>

是的,也许你已经注意到了,使用 post_class 函数时我们甚至不需要这样去写class=“post_class()”;

实例结果

结果如下post_class 是 WordPress 内置的一个用于显示文章 class 名称的函数,该函数通常会为每一篇文章生成独一无二的 class 值,如果你需要制作你自己的主题,而且还需要一点个性的话,那你最好驻足一下,使用该函数并配合灵活的 css 代码,我们可以制作出个性化十足的 WordPress 博客。

<post id="post-888"class="post-888 post type-post status-publish format-standard hentry category-2 tag-wordpress"> 文章内容 </post>

相关文章