WordPress调用指定ID的文章

WordPress 闲言碎语1 5.2K阅读模式

利用WordPress函数get_post(),调用指定ID的文章链接、标题及内容。

  1. <?php
  2.     $post_id = 1// 文章ID,可以在WP后台找到
  3.     echo get_post( $post_id )->post_content; // 输出文章的内容
  4. ?>

其它参数:

  1. // 调用方法:
  2. echo get_post( $post_id )->post_title; // 输出文章的标题
  3. // post_author      :文章作者的编号
  4. // post_data        :文章发表的日期和时间(YYYY-MM-DD HH-MM-SS)
  5. // post_data_gmt    :文章发表的格林尼治标准时间(GMT) (YYYY-MM-DD HH-MM-SS)
  6. // post_content     :文章内容
  7. // post_title       :文章标题
  8. // post_category    :文章类别的编号。注意:该值在WordPress 2.1之后的版本总为0。定义文章的类别时可使用 get_the_category()函数。
  9. // post_excerpt     :文章摘要
  10. // post_status      :文章状态(publish|pending|draft|private|static|object|attachment|inherit|future)
  11. // comment_status   :评论状态(open|closed|registered_only)
  12. // ping_status      :pingback/trackback状态(open|closed)
  13. // post_password    :文章密码
  14. // post_name        :文章的URL嵌套
  15. // to_ping          :要引用的URL链接
  16. // pinged           :引用过的链接
  17. // post_modified    :文章最后修改时间(YYYY-MM-DD HH-MM-SS)
  18. // post_modified_gmt:文章最后修改GMT时间(YYYY-MM-DD HH-MM-SS)
  19. // post_parent      :父级文章编号(供附件等)
  20. // guid             :文章的一个链接。注意:不能将GUID作为永久链接(虽然在2.5之前的版本中它的确被当作永久链接),也不能将它作为文章的可用链接。GUID是一种独有的标识符,只是目前恰巧成为文章的一个链接。
  21. // post_type        :(字符)(日志 | 页面 | 附件)

本站文章大部分始于原创,用于个人学习记录,可能对您有所帮助,仅供参考!

weinxin
我的微信
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
 
知更鸟
    • 自然鸟
      自然鸟 3

      调出的标题没链接啊!

    匿名

    发表评论

    匿名网友
    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

    拖动滑块以完成验证