|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
, s9 _" M( L. p3 {1 o2 b+ f1 q- \ ~: o7 r
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
5 N, f4 w0 e4 j5 B
* P$ _9 s6 z- a4 Z我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了' [, c# X* E4 f& s# c0 c
1 t- z5 s) I& l
方便实用 简单 何乐而不用呢- $ Z# U% h. C6 S6 A% A
- <?php
* }! A, G8 [% v
* P9 i6 d7 h, n1 s; j- define( 'ABSPATH', dirname(__FILE__) . '/' );& q( l. C" ?; P8 n8 Z
- require_once( ABSPATH . 'wp-config.php' );* |1 S, C/ z" B
- require_once( ABSPATH . 'wp-settings.php' );
* H$ Z# `: d+ O0 d - require_once( ABSPATH . 'wp-includes/class-wp.php' );! `/ m' K Q8 {' y
- require_once( ABSPATH . 'wp-includes/functions.php' );
2 W% p$ ` y9 J8 L; g3 S - require_once( ABSPATH . 'wp-includes/plugin.php' );
% U# k# v- B6 ?: Y) v) s; x3 ^ - $title = $_POST["title"];( m' k& f- S% p% f% P
- $content = $_POST["content"];
' @$ U7 x4 V; g: V/ {9 M' C$ ?1 Q - $tags = explode("_",$_POST["tags"]);3 f( [5 y i8 l: D: S# B2 c5 E7 K
- $cate = $_POST["cate"];
4 r1 L0 U' v7 @+ Z+ l+ z9 f - //print_r $tags;4 A0 ?% J/ X5 f) H X
- //
, j: G4 F- Y. I% E - //
. d# \, R/ Q5 [7 A4 h' Z - $wp = new WP();
# d, U; N7 J- d" Z* [$ A - $wp->main();# r! d! i/ j# s2 Y2 f7 B
- //" D# S" W5 k) ]
- $my_post = array();- r2 F; r, x7 p
- $my_post['post_title'] = $title;# e8 T1 A% }! B+ d
- $my_post['post_content'] = $content;: T2 a. X4 T; J6 w" Z
- $my_post['post_status'] = 'publish';
) ?4 b% \! A7 \ - $my_post['post_author'] = 1;" F- ^& `1 x3 ~1 |
- $my_post['post_category'] = array($cate);4 |6 Q% s q, u- \. P$ X
- $my_post['tags_input'] = $tags;
o9 I5 x0 |8 L1 N - //$my_post['tags_input'] = array('tag1', 'tag2');
2 ~$ r @* y; J9 q, e9 I3 h$ _ J - //$my_post['post_status'] = 'future';
; B" h- ?4 T, @) o, ^7 \6 h - ////$my_post['post_date'] = '2010-07-04 16:20:03';
4 c4 F8 J4 M) w: W( }3 Y - / _+ y& `* [* z! h# s2 n
- // Insert the post into the database$ Z: A6 A7 d8 Z1 r( T
- $ret = wp_insert_post( $my_post );7 Z$ ?# Y! p3 X9 F T
- echo $ret;
5 }" j7 f* ~- A5 i - ?>
: i1 l* R* m f( g8 j5 B: c
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ; t( a+ A* V/ l9 R. a
- <?php p. a7 y0 |$ A: [6 B$ I" o
- define( 'ABSPATH', dirname(__FILE__) . '/' );: Y3 ]+ u) Q! k9 U z
- require_once( ABSPATH . 'wp-config.php' );
7 l! p/ R3 G- ` - require_once( ABSPATH . 'wp-settings.php' );6 P( j8 P/ h. D8 ^. Q8 T
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
8 T' d1 P- m" [. K' [ - require_once( ABSPATH . 'wp-includes/functions.php' );
5 b5 _% V3 x7 t - require_once( ABSPATH . 'wp-includes/plugin.php' );
6 N1 e- A4 N; A - $pic_name = $_POST["pic_name"];
! f# a, [) ^8 W- P h2 z - $pic = $_POST["pic"];. i+ v, N% N- [; V; G: H" K u
- if($pic != "" && $pic_name != "")
7 R, T* G4 j' Z4 w' W3 [ - {1 c3 b/ x* S; q9 @
- $path = "images/";
8 a! ?1 }4 m* N# N - $pic_name = $path.$pic_name;
* S$ q9 z/ P- _& Q) d* B( T6 Y& D3 T - echo $pic_name;
- b- H1 ]1 l2 z- ~) `& z- X - echo "||";& R* U( C% V4 {% M
- error_reporting(0);
' e* j, G9 Q4 ?! ]1 w% d - mkdir("images");2 V: Y7 G& c, _9 `! J
- $handle = fopen($pic_name, 'w');1 v/ _" A% N, `
- echo fwrite($handle,file_get_contents($pic));5 L' c9 q9 j/ U- o, a) r
- }
) H1 n0 q6 o- v
$ y( Y' z3 M% ^6 W) y- $title = $_POST["title"];/ W# z4 v! f' T* b4 _% |* N
- $content = $_POST["content"];
. h) o" P J# w2 @) }2 a - $tags = explode("_",$_POST["tags"]);
* e2 ?5 a8 B/ d! V' }; ]% S - $cate = $_POST["cate"];9 ~) d* N8 o: Q1 S
- //print_r $tags;
, e1 F @4 Q# m) [1 i6 l% E - //
2 H5 s: m& E' V+ h! r+ `9 B' p/ x - //
* U0 i/ p! n" t* w - $wp = new WP();
1 \! V; }" d; B) g - $wp->main();9 E* T" {& _) O. `# d0 |2 i) k
- // r A4 ~4 O V9 u" |1 H
- $my_post = array(); N6 c% G, }, f0 @$ h6 E7 e; W
- $my_post['post_title'] = $title;
7 V2 @4 U* f* V- E$ t4 p# M' E9 J - $my_post['post_content'] = $content;+ w: |) L/ u! ] C& R- Q
- $my_post['post_status'] = 'publish';( V- E7 M1 x( z% \# W& _, x5 c# y
- $my_post['post_author'] = 1;
# q6 [4 c5 f7 i9 w1 Y. {2 U - $my_post['post_category'] = array($cate);) F% m5 O$ x/ x0 s7 ?
- $my_post['tags_input'] = $tags;( u. [& o& u0 I& Z( v
- //$my_post['tags_input'] = array('tag1', 'tag2');& A* Q- z/ H" _, H
- //$my_post['post_status'] = 'future';
/ M& R3 I$ {, b) P - ////$my_post['post_date'] = '2010-07-04 16:20:03';
: r) e" D9 U4 `) y# S! s8 F
3 B& F" L7 M! j* M- // Insert the post into the database( i0 n( E. z+ r: ]& H9 q3 _: D
- $ret = wp_insert_post( $my_post ); E& \. X% Q; i% Z
- echo $ret;
- s8 E2 t: i# N: d* e7 ] - ?>, v3 f+ X9 H3 ?8 ]
复制代码 我自己写的- O- l9 y4 T9 z
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|