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