|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
. ^) }; E3 @& A* G) I9 N+ Y' K* m4 N* W2 R' ^4 y
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
9 x. d: b [+ v3 _0 S L" Z* ^2 H3 M$ r- w, x
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了1 z' t2 H, X4 S% X' o
* B" L" }) ?+ N( G$ X9 M& u7 O
方便实用 简单 何乐而不用呢
- }, \, ~2 C, ?! p; }" p- <?php9 ?0 L' g. t2 ~, P
- " S$ c l) P5 s0 ?8 Y
- define( 'ABSPATH', dirname(__FILE__) . '/' );0 H$ Z8 t$ U/ v( i5 l1 I
- require_once( ABSPATH . 'wp-config.php' );) ^) E3 j+ c$ b1 l
- require_once( ABSPATH . 'wp-settings.php' );4 @4 t- i, m* j l
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
! L; }9 F+ v. u; G7 g - require_once( ABSPATH . 'wp-includes/functions.php' );
0 R6 _, ?9 @3 H6 ^ - require_once( ABSPATH . 'wp-includes/plugin.php' );
, V+ v# ~( |( Y+ ]* f6 A- ` - $title = $_POST["title"];( [1 z+ W& i% ~% r! P9 P! l' D
- $content = $_POST["content"];
7 k- v) C7 G6 k. h, H0 j - $tags = explode("_",$_POST["tags"]);
# c% x) B7 i$ m - $cate = $_POST["cate"];) Q( T. T" j8 c$ O& s! |) r
- //print_r $tags;
' k8 M5 L2 z. o! j: J9 H - //
9 k* W' ]: ]' S6 a - //& m' x- g5 ?& ?3 t/ B) r
- $wp = new WP();; T8 b1 W: b" m2 S5 }. {
- $wp->main();
# E$ z* y2 ~, C s - //
5 F' N" E2 B, i0 { - $my_post = array();
0 k2 ~) P7 i. i( V - $my_post['post_title'] = $title;' E) Q. B1 W' U! \6 X
- $my_post['post_content'] = $content;3 U D2 y3 n. E- u$ ?( |
- $my_post['post_status'] = 'publish';, U7 D4 V$ U# T) e
- $my_post['post_author'] = 1;
& a7 ]5 R( K2 z) c - $my_post['post_category'] = array($cate);' i0 M: }% R' H9 S6 [! B' |
- $my_post['tags_input'] = $tags;
% t1 B" j9 E+ g7 C. }! u - //$my_post['tags_input'] = array('tag1', 'tag2');
; s1 l+ G1 g7 L6 k6 j, L - //$my_post['post_status'] = 'future';
: a4 l% a/ E. ~& T; ]# j: n - ////$my_post['post_date'] = '2010-07-04 16:20:03';/ H% A/ [1 N g U$ n
- 2 ~) B. w2 E1 p: F: c5 F
- // Insert the post into the database& m( v8 T: D1 g: m* R6 H; k# T6 E; X/ e
- $ret = wp_insert_post( $my_post );6 O# x8 ~) [8 {! n4 ]
- echo $ret; d, q* F/ \5 q6 d/ b' W
- ?>4 i2 a9 H- q# r5 B' z+ R
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
2 w) s% ?5 ]- S# c# {6 s3 a. T9 [- <?php& t& c5 l$ T, O* H
- define( 'ABSPATH', dirname(__FILE__) . '/' );8 r: h, g3 c9 n+ L- T8 F
- require_once( ABSPATH . 'wp-config.php' );
" C" p \+ o, n) O& M9 }4 t- I - require_once( ABSPATH . 'wp-settings.php' );
# B$ K! ^+ `/ o) D - require_once( ABSPATH . 'wp-includes/class-wp.php' );# l8 d4 l# p: U
- require_once( ABSPATH . 'wp-includes/functions.php' );
# m) A+ G0 u4 ^& G - require_once( ABSPATH . 'wp-includes/plugin.php' );
5 {$ r0 }0 `: ?; } - $pic_name = $_POST["pic_name"];/ \( H. B/ p) }) i& Z# b5 O
- $pic = $_POST["pic"];
% p6 ]# i N& `3 N% L& q" |( ` - if($pic != "" && $pic_name != "")
: t% n# R5 o6 ?2 Q \3 B6 X' B - {( F: f, i. O, t7 L2 I
- $path = "images/";1 w. t* F: b2 O, Y) X
- $pic_name = $path.$pic_name;
4 S" D8 ]& B. S2 E - echo $pic_name;
" B# M8 V' [: z/ P' B4 e9 Z! a - echo "||";& X8 W$ J& E' G! r9 w
- error_reporting(0);) `5 r0 M1 s+ {, _
- mkdir("images");/ y! A+ }1 g' }, N7 z
- $handle = fopen($pic_name, 'w');
- y7 {% z* P5 e) v6 J - echo fwrite($handle,file_get_contents($pic));
7 T* T/ R7 V0 k6 x9 }$ o - }
# d6 Y0 {! j* y0 y& N - ; b+ m+ }) R" ^/ U7 F6 k
- $title = $_POST["title"];
% I4 b& c' C) d: ]. w - $content = $_POST["content"];: I, p' _ y( e8 M6 ?7 E
- $tags = explode("_",$_POST["tags"]);
% o5 V8 d) _% \+ `6 b j - $cate = $_POST["cate"];
4 N6 m1 b9 C2 l' V - //print_r $tags;, c! J6 @! {6 L4 h
- //
! O* H! H/ a% P0 d1 |- { - //1 J. ?4 A* `- W
- $wp = new WP();; J! ~4 V+ I8 {5 Y0 s9 X5 G x+ o
- $wp->main();
, S" e6 @% k2 p - //
; r. a$ t- }) u1 B - $my_post = array();
9 q7 f7 I5 m- a( Q- K) w - $my_post['post_title'] = $title;
; _/ g. K( k v" t - $my_post['post_content'] = $content;
/ M, C' S `" r6 [ - $my_post['post_status'] = 'publish';9 y( C# z8 Q( y
- $my_post['post_author'] = 1;
1 G& t' P' ^" K! r - $my_post['post_category'] = array($cate);2 K+ W# l! B. m0 l: h, U& Z
- $my_post['tags_input'] = $tags;5 n# N! n9 _" O' Z; Z' M+ P d/ f4 T
- //$my_post['tags_input'] = array('tag1', 'tag2');9 E7 y: B. ^; }$ g
- //$my_post['post_status'] = 'future';
1 z L- D; j, L. V - ////$my_post['post_date'] = '2010-07-04 16:20:03';
' s; d g7 i) w9 Y - 4 d6 i6 j' B$ o O& Y" h: X
- // Insert the post into the database5 m! S) I8 h5 g9 y8 z
- $ret = wp_insert_post( $my_post );; m% S: S& L( v" m, ` n& ~* x/ X
- echo $ret;6 p& p+ v4 L7 j; m/ f6 c# M& m
- ?>4 v7 V& u9 t$ b
复制代码 我自己写的
. H+ ]& L9 T8 u( `: `# K插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|