|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 7 \' c0 v6 X7 \0 |9 V7 I+ A3 s) f
; _* S- Z; d; c& i! t( s
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
5 q6 \$ v! s' U e1 o, i% M. X
+ p w' P$ z8 b我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了2 r$ n2 J. q) j5 i* A/ ]' k, [
4 w' f! T" q* R. d. d v
方便实用 简单 何乐而不用呢- - v; ~+ c% S( D8 v+ s* S/ z& Y
- <?php
. _: @. S2 b% l/ D4 c - / _' D1 J9 D( h% R
- define( 'ABSPATH', dirname(__FILE__) . '/' );
6 X; C- s; m" o& Q' T- S - require_once( ABSPATH . 'wp-config.php' );: Y% a- { I0 r0 a# x4 y
- require_once( ABSPATH . 'wp-settings.php' );
# l# {, u4 L! D2 l/ B: f5 T - require_once( ABSPATH . 'wp-includes/class-wp.php' );
$ ^: J$ n* g; ^4 ] - require_once( ABSPATH . 'wp-includes/functions.php' );
( b6 @! }' M4 V0 W! U - require_once( ABSPATH . 'wp-includes/plugin.php' );
( ~+ U2 o" |. Q* w2 M4 \ - $title = $_POST["title"];
" _( e8 v/ Y( U( F V - $content = $_POST["content"];
. Q2 B0 X* |0 J T$ q6 h8 e - $tags = explode("_",$_POST["tags"]);
; x- t8 l: S. V9 l" j- n8 Y3 N - $cate = $_POST["cate"];! g3 Y7 @$ K9 R( B8 n( G
- //print_r $tags;
5 j6 t7 _. W* S4 R& V: T - //8 S4 c; J: p3 a1 a V- o1 {2 }2 G
- //
: l1 z; S6 i9 K/ a$ e7 O - $wp = new WP();, w/ P7 f0 r6 j) O) u
- $wp->main();0 o$ c8 A+ ~- x' K; z- D. d. s
- //0 C5 f3 n+ c3 o- a, p0 p( t: G+ M U
- $my_post = array();4 m6 R+ n. ]6 F2 |8 r
- $my_post['post_title'] = $title;
- H/ E" T2 |9 o' w+ H- E' R( | - $my_post['post_content'] = $content;6 y+ R3 R) V. W. q4 K5 [- M: L7 K/ {
- $my_post['post_status'] = 'publish';
3 Q/ D& }. r! M( b/ H - $my_post['post_author'] = 1;
4 }! O& V" \) I4 J4 C+ G - $my_post['post_category'] = array($cate);
u9 G1 ?; Q6 ` - $my_post['tags_input'] = $tags;
5 e3 D8 j& g" g, @2 v( F - //$my_post['tags_input'] = array('tag1', 'tag2');+ D6 P& l# [( [% c+ f" N
- //$my_post['post_status'] = 'future';. f+ U* `" F0 ]" N0 D
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
% W {7 i R+ }( t, l7 n$ [ - ( |- M' o+ R* S" _- p, ~
- // Insert the post into the database' m& L6 k" m9 l0 m8 ?) H
- $ret = wp_insert_post( $my_post );
' [9 V% y' t. R3 P4 h& B" ^' H - echo $ret;2 x( c4 {5 A6 R& \
- ?>
' r2 N3 o: E8 E+ s/ i
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 3 h0 q) B0 N/ k; [
- <?php
2 O; a" q8 V/ Z& j7 g& u - define( 'ABSPATH', dirname(__FILE__) . '/' );
7 F6 X: D% H' G$ e( s1 n% C - require_once( ABSPATH . 'wp-config.php' );
2 _& k% _9 @2 G4 T1 o - require_once( ABSPATH . 'wp-settings.php' );4 w# \, h. m2 \8 _5 J$ h, Q, ]
- require_once( ABSPATH . 'wp-includes/class-wp.php' );, o+ |1 j8 l& i' p$ j( b
- require_once( ABSPATH . 'wp-includes/functions.php' );
( {- ]1 e; P6 F0 |* Q3 H - require_once( ABSPATH . 'wp-includes/plugin.php' );
: g* D5 ]5 L% J* k1 \4 D - $pic_name = $_POST["pic_name"];6 @" Y/ z4 t5 C5 F
- $pic = $_POST["pic"];
1 B) L; l0 O7 R4 b. ?" F8 c. [ - if($pic != "" && $pic_name != "")
0 o# ]- E w) ] z2 U( @3 X8 L5 P1 [9 s - {
6 A6 s, T0 A9 U* ?0 ]0 x5 C - $path = "images/";
/ N: v" I: L! ?: C - $pic_name = $path.$pic_name;4 L2 V. p; A( ~5 W- j# n
- echo $pic_name;- X% G8 f1 h2 H7 I; y* z
- echo "||";6 a7 ]) Z0 }% ^
- error_reporting(0);+ m4 I( k( x% |8 N
- mkdir("images");5 l: M5 }; b' I% S! _, Z
- $handle = fopen($pic_name, 'w');
' O( z* c6 f; M4 u4 o( {6 v6 J- m7 F - echo fwrite($handle,file_get_contents($pic));4 g- T% ?5 V4 t$ [, V) j
- }
' L/ b( U! S) O0 S1 l - 7 y! h8 b, R, X$ h. {5 N. Q1 k
- $title = $_POST["title"];' x" @$ y7 I \0 A2 w! o
- $content = $_POST["content"];
/ U! o/ g9 a3 l( V4 Q4 \. c) p1 ? - $tags = explode("_",$_POST["tags"]);
+ ?* s! `: E) G/ l7 [* L9 z - $cate = $_POST["cate"];6 i+ Z% r8 w& w# i, U w
- //print_r $tags;
3 f4 x$ \3 R4 t6 ~# K* P - //
& D7 v% R: y& U. L; L - //
. x7 S( X5 t# q. a% z - $wp = new WP();* c; M Y* o, `
- $wp->main();
$ D" n+ h9 ^. e$ `$ Z3 P r6 ]: I - //
: O) k+ T) c8 x) M- E" B - $my_post = array();
4 c, F/ v, ]4 X - $my_post['post_title'] = $title;
& I3 \6 ]2 Z( N) u% k2 x" s - $my_post['post_content'] = $content;
! L) z* c- `* U: @" D0 f - $my_post['post_status'] = 'publish';& W' j) ~0 {# ~! y7 Z! c3 U, h/ E
- $my_post['post_author'] = 1;% g$ K0 \4 w7 ^2 y; _6 X
- $my_post['post_category'] = array($cate);6 h9 y0 _# Y& d! [ t1 u$ h
- $my_post['tags_input'] = $tags;
( D% `# a2 d( B6 G; D* Z/ T - //$my_post['tags_input'] = array('tag1', 'tag2');
' g5 ^8 o/ x. `7 e1 r' ]2 u* j s - //$my_post['post_status'] = 'future';
$ E5 t1 B) v. b; v+ n- y( {+ ^ - ////$my_post['post_date'] = '2010-07-04 16:20:03';
8 J3 \8 o& Q# |
. x! O2 n8 E' O- s6 r. \, q; x- // Insert the post into the database3 T( P8 c6 V9 z" I" v
- $ret = wp_insert_post( $my_post );
4 f5 e8 p+ \5 c - echo $ret;
/ K$ L# O( H4 I0 J - ?>) I* a! M% O' d5 p ?& p
复制代码 我自己写的/ d$ H5 _- |+ f) ~* ~9 ~
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|