|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 ' o- k% y `3 K
$ o- e% G$ V6 O/ Q9 f
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
$ a; ?0 D# H6 W8 c, g+ O* m. T' P6 y- {3 M, m% h. @8 E4 g& X
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了# o' B* ]& C; Q
9 Z7 u+ H+ [7 F1 r+ u# Q
方便实用 简单 何乐而不用呢
# K0 n o7 s& M& ~: |- <?php: g5 s9 t/ C1 y! ]
$ x3 Y; ]7 b: H. K6 \- define( 'ABSPATH', dirname(__FILE__) . '/' );- b$ X$ b$ O7 ^0 i
- require_once( ABSPATH . 'wp-config.php' );
( ]7 Q; S' T7 Q- F* ^# s* @9 H - require_once( ABSPATH . 'wp-settings.php' );
7 A- [: a4 v, ~7 Z - require_once( ABSPATH . 'wp-includes/class-wp.php' );' l1 i& N, M6 Y8 l5 P
- require_once( ABSPATH . 'wp-includes/functions.php' );
1 f5 }; Y u. A- Y7 A4 \- c! g* } - require_once( ABSPATH . 'wp-includes/plugin.php' );) l* q1 S0 v5 i! f! n& H
- $title = $_POST["title"]; k# |/ ~" y' x. O5 M$ H
- $content = $_POST["content"];! N) r; e1 R- M1 }# K
- $tags = explode("_",$_POST["tags"]);
" [. B' ^( N( ]$ J; A9 S. {4 L T - $cate = $_POST["cate"];
2 a. a( F8 Z' S% ~5 p& z' K! B - //print_r $tags;* b. \7 u2 @; G$ B. R' j; E
- /// Z& C/ r7 D+ G, Z' w! d2 B
- //# n$ s$ M; b. u8 v0 t$ y
- $wp = new WP();6 s8 Y+ L: q" A8 b; G
- $wp->main();4 I/ Z" X8 `1 n2 r
- //
3 K4 h4 D8 ~ m* C0 m- g - $my_post = array();1 Y7 O* l7 V" c9 _0 o& h# h
- $my_post['post_title'] = $title;
- s5 X% g- f% n! A" r6 L0 i - $my_post['post_content'] = $content;
) q* A# j7 B$ ` - $my_post['post_status'] = 'publish';% u1 |: `5 c2 e7 w5 \: g, F- x
- $my_post['post_author'] = 1;
) g4 j2 r1 d, v5 R2 O1 w9 w - $my_post['post_category'] = array($cate);: m% ]& X+ R3 Y% z' u$ Z" k) f; p
- $my_post['tags_input'] = $tags;
( h; E, E$ }3 } - //$my_post['tags_input'] = array('tag1', 'tag2');
# E, k7 S, O9 j( G! e5 z! o) w$ g - //$my_post['post_status'] = 'future';
1 n) q2 F1 L7 p9 f7 w2 m/ ^ - ////$my_post['post_date'] = '2010-07-04 16:20:03';* k( H- q: B% n* Q; \* Y
- ) s* v/ V2 S! k
- // Insert the post into the database" b- s% Z4 L, L4 F! X
- $ret = wp_insert_post( $my_post );
9 g K) ^$ K v - echo $ret; H# [ G/ B$ ], G8 Y" E
- ?>2 Z& v2 `8 u( E& T
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
4 Q5 @5 n* L5 B# M! |8 j* g- <?php6 R* B0 l0 t1 r/ @- `* l+ G) ^. P; Y. w
- define( 'ABSPATH', dirname(__FILE__) . '/' );
e3 c g b" E& c$ c# k - require_once( ABSPATH . 'wp-config.php' );7 W- _1 Q) V& } X, h
- require_once( ABSPATH . 'wp-settings.php' );
, l) _7 V) o) p1 a8 b - require_once( ABSPATH . 'wp-includes/class-wp.php' );: ]/ H y+ W" f7 G+ E/ ^2 Q
- require_once( ABSPATH . 'wp-includes/functions.php' );$ L& E9 W2 K3 ]9 I/ @+ U
- require_once( ABSPATH . 'wp-includes/plugin.php' );( w) }" t: a) w% G6 e
- $pic_name = $_POST["pic_name"];
0 F- l+ J" m& k9 ~, d! h0 s- v/ i - $pic = $_POST["pic"];
/ M7 p, T2 o& c% f - if($pic != "" && $pic_name != "")$ J& K" u& B% t; P# M# i& o
- {
1 a: ]! e* k4 s ]- \3 u6 f# A - $path = "images/";5 a- D/ G ?- M0 A1 F
- $pic_name = $path.$pic_name;
! U3 _: H; f1 f; W - echo $pic_name;
$ f4 B5 a5 ]' c: _/ {2 w - echo "||";! y. m a$ D3 k- A- y' x
- error_reporting(0);4 K+ z4 T0 _* Z1 u' {
- mkdir("images");# m( a- h( p6 e$ I
- $handle = fopen($pic_name, 'w');
0 A* D5 N6 i+ u% J. |* R; e; [ - echo fwrite($handle,file_get_contents($pic));
( J2 d3 H! B0 J) L; p/ X, W% n" l - }3 ]" ^3 q7 H, c6 _
3 A: E" a G" H4 Y, ^( D, b- $title = $_POST["title"];7 w, q& }& s) e: w" e- K
- $content = $_POST["content"];8 v2 q; h6 A4 F0 z3 F
- $tags = explode("_",$_POST["tags"]);
6 r9 F/ p+ B( G0 ~8 s1 e. e9 S - $cate = $_POST["cate"];& n% X- E) T" x+ M6 G( A0 y
- //print_r $tags;: Q+ I) ^5 ], }! r( K9 C& n* A
- //' V6 G" q6 Z: v! ^
- //
6 r8 k. o5 d" u1 k7 J [& i( a - $wp = new WP();+ t7 {/ z% d% T" a0 m5 m+ W
- $wp->main();- u. w) W1 Q* _7 n" ^$ M
- //7 b9 ` y, F1 Z, z5 a" Q+ T
- $my_post = array();. g/ g9 E3 \! E3 I
- $my_post['post_title'] = $title;
( `5 Q, Z- w; V+ s% p# B6 B2 e - $my_post['post_content'] = $content;& a9 W1 W# ` [6 }
- $my_post['post_status'] = 'publish';: m( D! r& u! q) @( T0 j
- $my_post['post_author'] = 1;' u9 H% I8 R+ z$ y
- $my_post['post_category'] = array($cate);' S1 a5 j" v- }& g
- $my_post['tags_input'] = $tags;
7 g- O2 T* Y; z: Z; ^ - //$my_post['tags_input'] = array('tag1', 'tag2');
4 N m/ r8 S' L - //$my_post['post_status'] = 'future';1 o/ P& X( q7 T) Z! d
- ////$my_post['post_date'] = '2010-07-04 16:20:03';$ a' [% t( Q. i( ?- Q" \ @
* T% n; h8 s+ |- // Insert the post into the database
4 x; ]% R" m! r$ d6 W5 w - $ret = wp_insert_post( $my_post );. Y& d9 ~. W# H
- echo $ret;
9 S/ \+ h& d( K; k% k - ?>
, Z# }4 i# x* V$ p
复制代码 我自己写的
* x1 y. ~( Z6 x. {( s4 o插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|