|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 / e1 x4 {- H O8 O8 W% U* j
* P6 g' w0 C1 T+ k2 G( Q. v直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持1 G$ T0 w8 H( p) }( ~" `: z
9 h; P x8 u; Z2 L& k3 ]我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了6 @* R# C4 G' W' i4 x4 K a4 N+ c
; K- Z9 p% A, ^9 A7 l$ @* d方便实用 简单 何乐而不用呢- * j1 s* J. P; R5 q+ r7 A
- <?php
- @8 n" @* i/ W3 K; [ - + b7 a- \( C+ \8 H; M& T
- define( 'ABSPATH', dirname(__FILE__) . '/' );
3 p( M. N! K2 I$ P7 L' B' f3 L* q - require_once( ABSPATH . 'wp-config.php' );) X$ B- {, J: I' J; G+ @1 d+ L
- require_once( ABSPATH . 'wp-settings.php' );
8 i5 E9 ?0 {, a - require_once( ABSPATH . 'wp-includes/class-wp.php' );
( [. q8 g0 r* e - require_once( ABSPATH . 'wp-includes/functions.php' );$ r& K# z+ o" Q* j) Y" `$ i/ [" q5 D
- require_once( ABSPATH . 'wp-includes/plugin.php' );# z; K* G! F( I/ }
- $title = $_POST["title"];! V: M- F" Z% S
- $content = $_POST["content"];
: F9 t+ u9 a4 D9 k& l2 ? - $tags = explode("_",$_POST["tags"]);' T$ _' ~1 S0 p6 i) g" i) k
- $cate = $_POST["cate"];9 e3 R" F7 a) g" K6 W
- //print_r $tags;2 k1 Z' C7 Z6 x. j, X+ q& G
- //, }8 Y- Z& E' e* _/ [& _# V
- //! r1 [+ s8 n2 }
- $wp = new WP();6 x* @! ~$ C6 Z' Z3 O
- $wp->main();% t/ _: p7 N5 {1 i3 R9 K
- //- w- w5 q; I# G+ N6 C: Z* Z
- $my_post = array();
3 I1 m3 a9 X# w5 } - $my_post['post_title'] = $title;
' }" U5 d7 b$ ]' o - $my_post['post_content'] = $content;
2 n1 @5 m+ o7 g' m; q, e$ m8 ^# G - $my_post['post_status'] = 'publish';
2 b5 h/ d! H& i2 a' x - $my_post['post_author'] = 1;
* [) A% l( c7 A" | - $my_post['post_category'] = array($cate);( v; s6 U, V/ d1 `7 U) X) a4 z6 O
- $my_post['tags_input'] = $tags;
/ v) V6 H6 G/ m6 f - //$my_post['tags_input'] = array('tag1', 'tag2');
2 Y6 [$ W) `2 N p. r: q, m - //$my_post['post_status'] = 'future';
# c" b& ^1 g( t1 Q4 w2 Z - ////$my_post['post_date'] = '2010-07-04 16:20:03';/ b8 D. S0 N& ^+ H$ O
% v7 a/ P g5 ~7 s: {$ h- // Insert the post into the database- U) B! M9 W+ k9 K6 ^ A: E6 J
- $ret = wp_insert_post( $my_post );8 K7 n' N0 q' @ l9 |
- echo $ret;
' H4 f3 U: e' \: `5 i' g - ?>* e, j1 x( T. p5 f
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
1 N" l" f6 j1 g' c4 X9 \" W- <?php
# L, {9 u/ ]- e) n8 e! b - define( 'ABSPATH', dirname(__FILE__) . '/' );
' Q& M. W7 T6 A2 | c( S m - require_once( ABSPATH . 'wp-config.php' );
( C: g) \4 I: h0 h7 J9 v - require_once( ABSPATH . 'wp-settings.php' );
0 _- f4 @: @! | a# O - require_once( ABSPATH . 'wp-includes/class-wp.php' );
! a1 U, b. B: B - require_once( ABSPATH . 'wp-includes/functions.php' );. m9 h: b) H3 R/ ]( u. B
- require_once( ABSPATH . 'wp-includes/plugin.php' );
8 g% p7 Q4 E9 N5 l/ _2 u/ Y9 ~% u - $pic_name = $_POST["pic_name"];) R8 W; p/ x# z4 B; f0 H; }
- $pic = $_POST["pic"];- i% H- A& z" o' p/ Q
- if($pic != "" && $pic_name != "")/ h ?: {" `9 o5 B
- {8 R: Q9 q! z: U5 P9 J! |# S2 r
- $path = "images/";
1 i& j6 G% Q$ ~6 s7 w- V - $pic_name = $path.$pic_name;
G0 W" m; t1 J" h+ \, n - echo $pic_name;6 x5 n' a9 j$ Q# @, ?; _
- echo "||";
0 }6 J _% v( s$ K* g" w1 h2 ?4 u - error_reporting(0);9 H) B* c( o4 H
- mkdir("images");1 q/ Y* ~/ y8 r; ~
- $handle = fopen($pic_name, 'w');
" U+ w3 i) _, {0 c- Z - echo fwrite($handle,file_get_contents($pic));
2 X9 ?' ]2 _) N$ v, h C8 i9 c - }
$ c% z* o0 u G: z' | z2 |4 p
; L6 ^' m, S, u) f1 U: J; ~" ~! p; u- $title = $_POST["title"];
! P8 a: C' [5 F7 n$ e5 L! ` - $content = $_POST["content"];
5 L. H# P7 a$ O& @/ H& R! B; @ - $tags = explode("_",$_POST["tags"]);
% C1 g' a& H5 n. Z) N- Q' s - $cate = $_POST["cate"]; X' \% H% |; a8 u8 F
- //print_r $tags;
) e; M& b7 ^; s5 r* x - //
! L. K8 ^7 v( N' u2 y - // B& U. |* V, U8 s4 N
- $wp = new WP();& [& _) x! X; m
- $wp->main();' J7 N# Y- R) @/ Y
- //. ]) u& }! K3 q: i9 r
- $my_post = array();# o- d9 p- y/ N# g: D
- $my_post['post_title'] = $title;& p9 B/ r# @ e0 j
- $my_post['post_content'] = $content;1 d$ W0 L7 U- x7 q6 B
- $my_post['post_status'] = 'publish';
1 u* Y; }, z' K9 w; s - $my_post['post_author'] = 1;4 o- l! \4 t* B6 ]3 l
- $my_post['post_category'] = array($cate);4 D( p0 P/ I& N" X$ v5 o
- $my_post['tags_input'] = $tags;
$ e3 c, |$ \+ R g p - //$my_post['tags_input'] = array('tag1', 'tag2');' P" _) v! X: U1 \6 R! w3 p6 P
- //$my_post['post_status'] = 'future';+ a4 L7 b) v9 F
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
1 G0 B. B6 t5 ?9 E - 9 l; r9 I) ]8 P4 u1 h# u4 m- y
- // Insert the post into the database
3 ^8 @/ Q. d; X' d. q! o6 v - $ret = wp_insert_post( $my_post );1 V7 d( U5 F6 ?3 T( W4 I, {" h
- echo $ret;+ Z1 |, e, \6 W! g9 s# k+ E" a( J
- ?>/ Q1 `+ u7 J+ m& N& e
复制代码 我自己写的6 t1 ?9 F, Z5 h" B+ i/ v6 x$ I/ Y/ X% E
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|