WordPress $post变量检索信息的方法

追格官方小助手/ 2022年06月25日/ WordPress/ 浏览 957

我们在做WordPress主题开发时,有些主题标签是没法调用的,特别是一些复杂功能时。WordPress $ post具有更大的灵活性,可解决更多复杂性的问题,不妨看看:


$post–>ID – 当前文章的ID

$post–>post_excerpt – 文章摘要

$post–>post_title – 文章标题

$post–>post_type – 返回分类类型,包括自定义分类、page或者post

$post–>post_date – 检索发布文章的时间戳

$post–>post_status – 检索文章的状态:发布,私有,草稿,等待复审

$post–>post_content – 检索所有文章内容以及任何标记.

$post–>post_name – 检索帖子的别名

$post–>guid – 文章 Url

$post–>post_author – 文章作者

$post–>post_category – 检索文章类别

$post–>post_parent – 父页面,用于创建自定义导航元素

$post–>comment_count – 返回文章的评论数量


示例:

<?php if (have_posts()) : while (have_posts()) : the_post();
$yourvariable = $post->post_content;
endwhile; endif; ?>


发表评论

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

客服 工单