如何通过zblog的GetPost函数调用指定文章或页面的数据?zblog技术教程
来源:博客吧 浏览:657次 时间:2021-05-18 20:16:12
在zblog后台页面管理中创建一个网站简介页面,如果想在网站首页调用这个页面的标题、内容或指向链接,可以使用Z-Blog的内置函数GetPost完成,该函数的作用是通过指定的ID、标题或别名等参数获取指定文章、单页面或其它类型的Post表的数据,包括不限于标题、内容等。
函数代码
1 2 |
//返回id为10的Post对象实例,如果没有就返回一个空的Post对象实例
$post = GetPost(array('id'=>10)) //返回object(Post类型) |
array参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
array( 'id' => 10, //指定 ID(可省略) 'title' => 'abc', //指定 Post 标题(可省略) 'alias' => 'cba', //指定 Post 别名(可省略) 'titleoralias' => 'ddd', //指定 Post 标题 or 别名(可省略) 'idorname' => 'fff', //指定 Post 的 ID 或标题 or 别名(可省略) //以下是原$option 参数的 key 键
'post_type' => null, //指定查询 Post 表的类型 (可省略) 'post_status' => null, //指定查询 Post 表的状态 (可省略) 'only_article' => false, //指定是查找文章 (可省略) 'only_page' => false, //指定是查找页面 (可省略) 'where_custom' => array(array('=', 'log_Template', '')), //自定义 where 'order_custom' => array('log_CommNums' => 'ASC'), //自定义 order ) |
代码示例
获取指定ID页面的数据
1 2 3 4 |
$aboutPage = GetPost(array('id'=>2)); //或直接把 array('id'=>2) 换成 2 {$aboutPage.Title} //页面标题 {$aboutPage.Content} //页面内容 {$aboutPage.Url} //页面URL |
获取指定标题页面的数据
1 2 3 4 |
$aboutPage = GetPost(array('title'=>'网站简介')); {$aboutPage.Title} //页面标题 {$aboutPage.Content} //页面内容 {$aboutPage.Url} //页面URL |