|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 8 @/ n" M }8 S+ R
& j. Z& `- ?4 D) {( q5 y0 J: v直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持 W1 [; v" x2 S5 N
1 Q2 A& z; |5 P2 h/ ^6 G* t. \9 X我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
" p5 d* ?( `$ v7 {2 d( U9 f
4 {1 \' U1 G8 C& \ b9 `# F方便实用 简单 何乐而不用呢
) \" u3 t% i5 U l" @/ B- <?php0 P% _5 n2 w. N9 O1 t% F* E
) ?* [7 L* Q) P- define( 'ABSPATH', dirname(__FILE__) . '/' );
" b9 S& W. `9 e7 K! e; J - require_once( ABSPATH . 'wp-config.php' );1 z5 C' R9 x+ R# o/ A5 U0 E
- require_once( ABSPATH . 'wp-settings.php' );
( w) X4 U, O+ N0 }- N0 R4 { - require_once( ABSPATH . 'wp-includes/class-wp.php' );
. r3 [4 y+ v/ V% a* Y1 c - require_once( ABSPATH . 'wp-includes/functions.php' );
* x( c% g1 O- l* }# g! f2 b8 ]- u - require_once( ABSPATH . 'wp-includes/plugin.php' );' D. g/ J& d1 {
- $title = $_POST["title"];
0 I# J0 Y. g) k! ]3 k' ]. G9 c - $content = $_POST["content"];
2 n4 G4 c; \, C- z3 ~/ g5 T! d - $tags = explode("_",$_POST["tags"]);
) _0 W( Z( S9 N" Z - $cate = $_POST["cate"];
/ B0 }" u8 Q0 q+ @, S+ J! Q& B' d - //print_r $tags;5 ]- G, m0 |+ S( f& j$ e7 G' Y
- //
7 A- M x* U0 X# {" H - //7 o! u4 J* k1 i: e1 c
- $wp = new WP();
, V* n3 u+ ~/ G2 W; C - $wp->main();( w5 i. \. C! k. Z# D6 T3 q
- //
( N! }/ i& r" ~; c, i) \ - $my_post = array();# a0 U' `& Q, s; B% W
- $my_post['post_title'] = $title;
4 K9 ]. }" @- Y - $my_post['post_content'] = $content;
, r% [" J) i$ t, H6 ?9 ?6 x: T7 B - $my_post['post_status'] = 'publish';. u$ ?' ~" z- Y" ` X, O* p6 X
- $my_post['post_author'] = 1;
, |" |( p$ n; P# ~- G - $my_post['post_category'] = array($cate);
. P+ W4 G5 l' w3 Q - $my_post['tags_input'] = $tags;4 z& H7 ]1 _/ q
- //$my_post['tags_input'] = array('tag1', 'tag2');
8 |" J/ b" |! d. Q/ N - //$my_post['post_status'] = 'future';+ I4 n" y9 y/ Q0 ^, P
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
& z6 K @( M7 l: G - ( {, ?# }7 A x' E3 _/ ?) t
- // Insert the post into the database, o3 Q. h! J- e. R" W
- $ret = wp_insert_post( $my_post );
) `$ A- f+ k( `! G, D/ [ - echo $ret;) _8 F( w5 c7 ]( Q' u' n
- ?>+ h+ I7 u/ H+ l7 Z9 A+ u
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 4 a8 o7 J; \' n& y$ b. O9 q' L, a5 U
- <?php0 P3 T/ T7 j6 V; Q$ T8 ~
- define( 'ABSPATH', dirname(__FILE__) . '/' );
6 r- ?& E& m. n) }9 \7 Q: \1 Q - require_once( ABSPATH . 'wp-config.php' );
: c% i8 [- c, j* A- F" ?& @" d7 ` - require_once( ABSPATH . 'wp-settings.php' );
: I* a, Q9 F! G: b/ M - require_once( ABSPATH . 'wp-includes/class-wp.php' );0 @' S+ R* J% H1 `2 F3 e3 i# P
- require_once( ABSPATH . 'wp-includes/functions.php' );
0 e% v# M5 J6 e# b N5 W" E - require_once( ABSPATH . 'wp-includes/plugin.php' );! j4 y2 G# c+ c$ N6 C' \! W/ V
- $pic_name = $_POST["pic_name"];
8 @ ~( ^( q- C3 Q - $pic = $_POST["pic"];5 V8 `7 Y' g+ o+ K# r* q% Y# I
- if($pic != "" && $pic_name != "")
. L. B1 V J+ A8 s% e - {) y+ s4 m q# p1 q8 m
- $path = "images/";* W/ {1 ~. V H% ? o k
- $pic_name = $path.$pic_name;
6 L- Y+ q* \+ _4 w0 ^4 n - echo $pic_name;
6 H0 | i+ Q2 h* s7 u/ {$ [; f - echo "||";2 \1 p7 M+ w8 x3 V
- error_reporting(0);
2 ?2 }6 }: M0 ] - mkdir("images");
1 ]- r9 L7 r4 Y' f4 z9 m - $handle = fopen($pic_name, 'w');
) k9 [1 u# j# u) g$ @ - echo fwrite($handle,file_get_contents($pic));
' Z$ l5 D6 S2 d$ P - }
7 K' a& H. @0 l- o
. d- U/ j, G# Q, W& `$ ?5 x- $title = $_POST["title"];- Y- x/ E# Q& p7 f$ q: }
- $content = $_POST["content"]; A+ f0 g- M. h& s5 [
- $tags = explode("_",$_POST["tags"]);+ k. M, c0 i* c! V8 I& `& J9 Q
- $cate = $_POST["cate"];
% u6 h. q' U V L - //print_r $tags;) h7 N9 z e1 G) F
- //( R. i% p( }" D1 H( P
- //
& r2 h! F1 ?8 e( Y' C - $wp = new WP();
- t: C1 N; ?0 h0 M - $wp->main();
( G: ~6 T" N! S - //* z) W7 L" L$ _2 M& D4 j
- $my_post = array();
, @& ]- l3 ?. S - $my_post['post_title'] = $title;6 h' c) I, M& v1 v* i0 G
- $my_post['post_content'] = $content;+ m; r1 B3 U" M
- $my_post['post_status'] = 'publish';
) h: f: b% d" f( o$ _6 K - $my_post['post_author'] = 1;
; f& f0 J" u! U3 H1 I - $my_post['post_category'] = array($cate);
1 E0 [ d, n# Q7 o; [/ s, c - $my_post['tags_input'] = $tags;
. I/ w' l1 `% l8 n2 _0 x y - //$my_post['tags_input'] = array('tag1', 'tag2');; B2 Y+ ~+ W$ ~! ?0 O& O3 |, {
- //$my_post['post_status'] = 'future';
6 l7 u& q. O/ _9 k/ s3 Z$ X& E0 S! F0 A - ////$my_post['post_date'] = '2010-07-04 16:20:03';) c' d! Z* {* c8 r' R
3 y6 g! m0 c' a7 `8 ^- // Insert the post into the database
% k1 g- s1 D) D2 p3 {' X; l6 r - $ret = wp_insert_post( $my_post );5 r6 o" p3 z' O$ s. r
- echo $ret;
7 f5 P& I4 k$ Z% X - ?>* j( |( ^* }1 ~: ~% K0 I
复制代码 我自己写的
+ {- F5 |) J3 f0 n插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|