PHP学习笔记之获取文章内容(2种方法)
来源:互联网 发布:知乎最好的答案 编辑:程序博客网 时间:2024/06/05 10:02
theme/../page.php
<?php/** * The template for displaying all pages * * This is the template that displays all pages by default. * Please note that this is the WordPress construct of pages * and that other 'pages' on your WordPress site will use a * different template. * * @package WordPress * @subpackage Twenty_Twelve * @since Twenty Twelve 1.0 */ini_set('display_errors',true);error_reporting(E_ALL);echo "测试查询数据库返回数据<br/>";$postID = $_GET['page_id'];echo "postID = $postID<br/>";//1.通过get_post()方法获取contentecho get_post($postID)->post_title;echo '<br />';echo get_post($postID)->post_content;echo "<br/>";//2.通过wpdb sql 查询方法获取content/*$fivesdrafts = $wpdb->get_results( "SELECT * FROM $wpdb->postsWHERE ID = $postID");echo "输出数据库查询数据<br/>";foreach ( $fivesdrafts as $fivesdraft ) {echo $fivesdraft->post_title;echo $fivesdraft->post_content;}*/die();?>
<?php/** * The template for displaying all pages * * This is the template that displays all pages by default. * Please note that this is the WordPress construct of pages * and that other 'pages' on your WordPress site will use a * different template. * * @package WordPress * @subpackage Twenty_Twelve * @since Twenty Twelve 1.0 */ini_set('display_errors',true);error_reporting(E_ALL);$postID = $_GET['page_id'];//1.通过get_post()方法获取content//echo get_post($postID)->post_title;//echo "<br/>";//echo get_post($postID)->post_content;//echo "<br/>";echo json_encode(get_post($postID)->post_content);//2.通过wpdb sql 查询方法获取content/*$fivesdrafts = $wpdb->get_results( "SELECT * FROM $wpdb->postsWHERE ID = $postID");echo "输出数据库查询数据<br/>";foreach ( $fivesdrafts as $fivesdraft ) {echo $fivesdraft->post_title;echo $fivesdraft->post_content;}*/die();?>
<?php/** * The template for displaying all pages * * This is the template that displays all pages by default. * Please note that this is the WordPress construct of pages * and that other 'pages' on your WordPress site will use a * different template. * * @package WordPress * @subpackage Twenty_Twelve * @since Twenty Twelve 1.0 */ini_set('display_errors',true);error_reporting(E_ALL);$postID = $_GET['page_id'];//1.通过get_post()方法获取content/*echo get_post($postID)->post_title;echo "<br/>";echo get_post($postID)->post_content;echo "<br/>";*/$post_content = get_post($postID)->post_content;$pageContent = array('content' => strip_tags($post_content));var_dump($pageContent);die();echo json_encode($pageContent);//2.通过wpdb sql 查询方法获取content/*$fivesdrafts = $wpdb->get_results( "SELECT * FROM $wpdb->postsWHERE ID = $postID");echo "输出数据库查询数据<br/>";foreach ( $fivesdrafts as $fivesdraft ) {echo $fivesdraft->post_title;echo $fivesdraft->post_content;}*/die();?>
0 0
- PHP学习笔记之获取文章内容(2种方法)
- php实现获取文章内容第一张图片的方法【转】
- php实现获取文章内容第一张图片的方法【转】
- 如何使用php自动获取文章内容关键字
- 学习笔记之php页面中js获取标签元素的ID值方法
- 【小白笔记】PHP学习之路 (16) --数组(增删、获取元素)
- PHP学习笔记之预先获取文章中图片尺寸(app专用)
- php学习笔记(四)魔术方法
- Struts2学习笔记之动态方法调用和参数获取
- Struts2学习笔记之动态方法调用和参数获取
- 学习笔记之三 获取系统时间的方法汇总
- 【Darwin学习笔记】之获取系统处理器数量的方法
- java学习笔记之class类实例获取方法
- 【Darwin学习笔记】之获取系统处理器数量的方法
- 【Darwin学习笔记】之获取系统处理器数量的方法
- PHP文章内容分页函数
- PHP处理小说文章内容
- php之cURL学习笔记2
- duilib 动态创建按钮
- C++利用ADO连接Access
- CodeforcesBeta Round #19 D. Points(线段树)
- Spring related resource
- Opencl基本术语
- PHP学习笔记之获取文章内容(2种方法)
- android jni代码编写规则--整理总结
- redis集群
- for loop initial declaration used outside C99 mode
- 二路归并排序
- android 多线程断点续传下载 一
- app banner设计
- HDU 2833 WuKong 最短路径+DP
- CentOS 64位 安装32位运行库