wordpress主题开发get_post()笔记
2018-03-16 11:42
295 查看
在主题开发中经常需要在非文章页面或者分类页面调用某一篇文章的标题,简介等信息,所以就需要单独得获取这些指定的文章,而文章的唯一的标记的就是该篇文章的ID,那如何获取文章的ID呢,在我的其他博文里面有“wordpress获取当前页面的ID”: 根据ID获取文章内容需要用到get_post($id)方法: $id: 可以是对应的ID值,或者是变量,但最好是变量 $result = get_post($id) 其返回值:$result 是一个对象,打印出来: WP_Post Object
(
[ID] => 344
[post_author] => 1
[post_date] => 2017-08-04 15:19:42
[post_date_gmt] => 2017-08-04 07:19:42
[post_content] => 页面内容
[post_title] => 服务简介
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => 服务简介
[to_ping] =>
[pinged] =>
[post_modified] => 2017-08-04 16:59:26
[post_modified_gmt] => 2017-08-04 08:59:26
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://localhost/wordpress/?page_id=344
[menu_order] => 0
[post_type] => page
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
获取其信息 就可以用类似于 $result -> post_title 的方法,实现信息调用。
(
[ID] => 344
[post_author] => 1
[post_date] => 2017-08-04 15:19:42
[post_date_gmt] => 2017-08-04 07:19:42
[post_content] => 页面内容
[post_title] => 服务简介
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => 服务简介
[to_ping] =>
[pinged] =>
[post_modified] => 2017-08-04 16:59:26
[post_modified_gmt] => 2017-08-04 08:59:26
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://localhost/wordpress/?page_id=344
[menu_order] => 0
[post_type] => page
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
获取其信息 就可以用类似于 $result -> post_title 的方法,实现信息调用。
相关文章推荐
- wordpress主题二次开发笔记
- iOS小明开发笔记(二十六) (同步、异步请求, GET、POST请求)
- iOS开发笔记>> socket, http(post, get), TCP/ IP
- ios开发笔记—get请求和post请求简单代码
- WordPress开发中的get_post_custom()函数使用解析
- IOS开发笔记-NSURLConnection同步请求和异步请求以及get方法,post方法
- WordPress开发中的get_post_custom()函数使用解析
- 【Cocos2d-x游戏引擎开发笔记(24)】CURL实现get和post联网
- 详解WordPress开发中的get_post与get_posts函数使用
- 【Cocos2d-x游戏引擎开发笔记(24)】CURL实现get和post联网
- iOS海哥开发笔记 (海哥原创,iOS 之同步请求、异步请求、GET请求、POST请求 )
- 【Cocos2d-x游戏引擎开发笔记(24)】CURL实现get和post联网
- iOS陆哥开发笔记(二十七) (同步、异步请求, GET、POST请求)
- WordPress主题开发实例:get_term_by()获取指定分类链接
- android开发学习笔记(一)分别通过GET和POST请求从服务器端获取数据
- WordPress 主题开发 - (十) Single、Post及404模板 待翻译
- wordpress 主题开发常用笔记
- WordPress主题开发:get_term_by和get_term_link
- iOS开发网络篇—发送GET和POST请求(使用NSURLSession)
- wordpress主题开发:导航菜单函数wp_nav_menu()使用方法