当前浏览:首页 / WordPress函数 / the_post()

the_post()

在循环中迭代post索引

postmore...

themore...


更多信息

基本用法

if ( have_posts() ) {
	while ( have_posts() ) {

		the_post(); ?>

		<h2><?php the_title(); ?></h2>

		<?php the_content(); ?>

	<?php }
}


源码

查看源码 官方文档


更新日志

版本描述
1.5.0开始引入

使用示例

  • 示例1

    函数the_post()检查循环是否已启动,然后通过每次移动到队列中的下一个post来设置当前post

  • 示例2

    根据开发文档,在循环中访问post的可用函数有:

    • next_post_link() – 指向在当前文章之后按时间顺序发布的文章的链接
    • previous_post_link() – 指向在当前文章之前按时间顺序发布的文章的链接
    • the_category() – 与正在查看的文章或页面关联的一个或多个类别
    • the_author() – 文章或页面的作者
    • the_content() – 文章或页面的主要内容
    • the_excerpt() – 文章主要内容的前55个单词,后面是省略号(…)或指向全文的阅读更多链接。您还可以使用文章的“摘录”字段自定义特定摘录的长度。
    • the_ID() – 文章或页面的ID
    • the_meta() – 与文章或页面关联的自定义字段
    • the_shortlink() – 使用网站的url和文章或页面的ID指向页面或文章的链接
    • the_tags() – 与文章关联的一个或多个标签
    • the_title() – 文章或页面的标题
    • the_time() – 文章或页面的时间或日期。这可以使用标准的php日期函数格式进行自定义。

    包括以下条件标签:

    • is_home() – 如果当前页面是主页,则返回true
    • is_admin() – 如果在管理界面内,则返回true,否则返回false
    • is_single() – 如果页面当前显示单个文章,则返回true
    • is_page() – 如果页面当前显示单个页面,则返回true
    • is_page_template() – 可用于确定页面是否使用特定模板,例如:is_page_template('about-page.php')
    • is_category() – 如果页面或文章具有指定的类别,则返回true,例如:is_category('news')
    • is_tag() – 如果页面或文章具有指定的标记,则返回true
    • is_author() – 如果在作者的存档页面内,则返回true
    • is_search() – 如果当前页面是搜索结果页面,则返回true
    • is_404() – 如果当前页面不存在,则返回true
    • has_excerpt() – 如果文章或页面包含摘录,则返回true