|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 / D O& ?1 T" m7 M$ S6 x6 {
5 x: c2 t* `% O+ g直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持" b: ?3 W) M7 m8 ^( H; P" \
7 ]! }$ s% G( \/ Z# W, s我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了: u. v4 V+ l6 u- z, o, q
- N! H8 c# f! y
方便实用 简单 何乐而不用呢
& m4 k+ K0 E: r' S% t% z( c- <?php$ O) b* F( n$ K# M+ Z
- , |. n3 Y+ u. E' P) I# B
- define( 'ABSPATH', dirname(__FILE__) . '/' );
7 n/ }! U7 z5 M' s - require_once( ABSPATH . 'wp-config.php' );
- `2 Z: }1 `: ?0 e0 a. V7 h - require_once( ABSPATH . 'wp-settings.php' );7 K, d8 Z, X" c, C% U) @4 ?
- require_once( ABSPATH . 'wp-includes/class-wp.php' );6 A0 e; f" a6 K$ ]" \0 p5 A: s, {
- require_once( ABSPATH . 'wp-includes/functions.php' );
2 w4 w% b H* E4 O! w" e - require_once( ABSPATH . 'wp-includes/plugin.php' );6 X' `& R+ r4 z& f' L) y) r& e
- $title = $_POST["title"];" n& c2 p$ r6 y2 |
- $content = $_POST["content"];
. C" x4 L* q! [. J - $tags = explode("_",$_POST["tags"]);
1 [& s; ?: n! V5 d! B' |& M - $cate = $_POST["cate"];6 q9 a' K3 Q0 \7 e
- //print_r $tags;9 |) O, d. R' y8 d( r$ B9 W
- //
# @! c( e- D! o3 r' W7 { - //: t# Y9 d& f! [/ L* G
- $wp = new WP();
! b4 o/ }! m4 q, n. g6 S. z" C - $wp->main();
. ^& |" e3 i5 X8 [# Z/ A - //- P Y# G; J3 v" h$ A) F$ E# j. C
- $my_post = array();
6 p. R7 O4 J5 s* s8 x5 I/ y7 R - $my_post['post_title'] = $title;' F# I4 J% U0 q8 l( v0 K2 ~ [- T
- $my_post['post_content'] = $content;
4 p! y- k+ H. h - $my_post['post_status'] = 'publish';
: e. Z/ T [6 e* W - $my_post['post_author'] = 1;
8 U& k$ a/ p5 [) Z9 z - $my_post['post_category'] = array($cate);, c% u7 r$ @" o/ }4 m+ T
- $my_post['tags_input'] = $tags;# R1 k' j7 v: R* o+ I+ [) O( m, B6 N
- //$my_post['tags_input'] = array('tag1', 'tag2');
# @4 Z3 h# f* n/ V8 m! @ - //$my_post['post_status'] = 'future';$ C) ]# U$ H6 o
- ////$my_post['post_date'] = '2010-07-04 16:20:03';* d+ F* [! Q% z1 B
- % t$ r, q: e2 k7 a5 m7 X
- // Insert the post into the database
' h$ H6 j9 s4 C h. W+ m/ Y - $ret = wp_insert_post( $my_post );
( {7 ^2 k0 ]4 O0 K9 \2 u - echo $ret;$ L$ C, o: z6 k2 H0 w' w m8 `
- ?>) [( W1 @+ E; x2 ^+ }9 O* A, M V7 E
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- . k8 H0 Y, V: P) h; q
- <?php
s# _" c3 X+ h; L, M' [ - define( 'ABSPATH', dirname(__FILE__) . '/' );
) c) h6 _7 x$ ?% G - require_once( ABSPATH . 'wp-config.php' );
. l/ v( P- b( o5 b - require_once( ABSPATH . 'wp-settings.php' );
' h* g" `, \; s7 j* b. {) Y - require_once( ABSPATH . 'wp-includes/class-wp.php' );# Z/ w1 n w4 ^5 |' ^( l
- require_once( ABSPATH . 'wp-includes/functions.php' );
: q$ [) z' a% ?. V* V7 ^- p - require_once( ABSPATH . 'wp-includes/plugin.php' );
: y( U1 D( k ?# i { - $pic_name = $_POST["pic_name"];1 x: l0 z( @- i7 p C7 r
- $pic = $_POST["pic"];
) C& |4 d0 h J4 X - if($pic != "" && $pic_name != ""), {" G$ X# ~9 s: U7 z& L: I
- {
/ S" b9 Z, [, r9 E5 g - $path = "images/";+ V2 h3 v. w8 X
- $pic_name = $path.$pic_name;
- F9 F8 k0 j) H7 W - echo $pic_name;& F, R$ I8 }8 z
- echo "||";, u% j9 ]+ b1 c; X4 I5 U- n @
- error_reporting(0);
& P* U( O6 i5 |( ^$ b! g9 a( z - mkdir("images");
, A6 s' _% z3 q) k" T. K - $handle = fopen($pic_name, 'w');
; m' }8 L6 h' t& c2 U, P - echo fwrite($handle,file_get_contents($pic));$ Q# T! F: Q. V
- }
' k( l- \. o9 O' U5 R! O - 8 C5 k$ n$ F) [1 x9 Q
- $title = $_POST["title"];
5 o, m( ^3 C2 V' v/ j0 y6 B - $content = $_POST["content"]; C0 I2 q1 D0 m" V7 N; r) w3 [# @
- $tags = explode("_",$_POST["tags"]);
5 {% b% g) @1 M7 c - $cate = $_POST["cate"];, Q: n( ^* E$ S
- //print_r $tags;% L; \5 v% ?0 W* f w E
- //- j* k5 ~( r8 c" q& o2 c0 y' O
- //" w) j: b# ^; c) E/ a7 D
- $wp = new WP();. W Q& k9 h& l# D& I
- $wp->main();
d: p; E: t0 |" i) B Q8 N0 e) f - //
9 K# Y0 T. @' n, Q, z - $my_post = array();7 f" i0 \+ ?& B/ G0 \
- $my_post['post_title'] = $title;/ ]$ \3 g; ]1 @) U/ d- L: o* `5 R
- $my_post['post_content'] = $content;7 I2 W/ C1 L7 I R
- $my_post['post_status'] = 'publish';5 @7 a- X0 b7 z! d- p" [9 M' x
- $my_post['post_author'] = 1;8 U( m& o! K! Q) f. P
- $my_post['post_category'] = array($cate);
# l: s/ i: H. E. {& z3 z+ f0 v - $my_post['tags_input'] = $tags;
6 L" u3 _8 u1 U) n- d4 k - //$my_post['tags_input'] = array('tag1', 'tag2');
, D; i- {4 O. e, H2 R - //$my_post['post_status'] = 'future';
! ^. {& d6 W Y" T - ////$my_post['post_date'] = '2010-07-04 16:20:03';8 H" S) z' h% v& j
D! W+ w+ |# N; j" e7 h7 |- // Insert the post into the database, O$ f8 v8 m- l: x4 A
- $ret = wp_insert_post( $my_post );# L+ J9 z z3 w+ V! F9 l9 l
- echo $ret;
; c7 u7 \! F+ _. F# m& s( t. d - ?>0 h! F' j+ ]2 A a& t
复制代码 我自己写的
( h4 t) x0 H9 T1 o6 E& |插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|