|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
* K( v9 V) ~/ D; ?9 d) O+ u' C. u3 m- J, @& J: y# {
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
* P$ o) f6 V- k9 g. S2 K a7 _; m' Z( Y+ D4 Z, u8 A* C2 h
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
: s: t$ ^$ ?+ J$ L3 I0 f6 T6 F0 ?1 p% _% `2 `. a! n/ z/ U
方便实用 简单 何乐而不用呢
7 O( Y, \1 Y8 q) R* v: p/ _- <?php) P% I; e" y2 g1 M
- 1 V5 W$ w+ E8 |* @
- define( 'ABSPATH', dirname(__FILE__) . '/' );9 U6 I/ i6 }. s( q& r- N) B; l
- require_once( ABSPATH . 'wp-config.php' );
9 `1 D( m1 T0 i+ c9 v, {/ h$ c - require_once( ABSPATH . 'wp-settings.php' );
1 z- V# @8 A# o, l5 I# L* g5 i3 ?$ Y - require_once( ABSPATH . 'wp-includes/class-wp.php' );
, B0 o/ b5 ^2 q4 z' o - require_once( ABSPATH . 'wp-includes/functions.php' );
. D( d3 O$ A( D5 a - require_once( ABSPATH . 'wp-includes/plugin.php' );- `' y F0 Q% r$ m
- $title = $_POST["title"];4 l8 A+ g3 `/ y2 k7 C0 m& B& K! y
- $content = $_POST["content"];0 h- x' U3 h8 T5 s: k
- $tags = explode("_",$_POST["tags"]);! t9 U- K: H* U, A5 f
- $cate = $_POST["cate"];
! i1 n! A/ K" ^3 x7 R9 q {" F - //print_r $tags;; ^/ C d- E# f' J4 Y
- //" ?( w9 l5 V. }, H [4 g3 E
- //5 K: T3 H5 z$ T& W
- $wp = new WP();
* l4 @2 X) I1 ^$ q, } e! A# ~ - $wp->main();! U- l5 u6 c2 ^8 E% v" T/ h
- //
1 O( d, A) a1 W' Q) E7 h3 z4 T/ F% M - $my_post = array();
; G. t7 x$ I2 s/ ? - $my_post['post_title'] = $title;
) B: E% S8 q5 ]* R. V( G - $my_post['post_content'] = $content;
# U$ W& \. B$ m* G0 n% \, h - $my_post['post_status'] = 'publish';, m) o1 t$ O* p% p4 b5 L- X8 o% u
- $my_post['post_author'] = 1;& f4 Y/ j4 B% t0 K
- $my_post['post_category'] = array($cate);2 ^+ T! Q9 q: C* m Z. I4 U+ I6 k
- $my_post['tags_input'] = $tags;% p. @7 r: j- D9 a* G' j- c
- //$my_post['tags_input'] = array('tag1', 'tag2');
& }6 `( {- Y) B7 J - //$my_post['post_status'] = 'future';
# q3 C( X8 ] T% G, F - ////$my_post['post_date'] = '2010-07-04 16:20:03';
+ E, [7 w+ U G8 o. {' D, r- ^: g2 @ - * B8 w7 W. ~7 b2 m2 q
- // Insert the post into the database& k( {( S: T9 d( B) Y' K
- $ret = wp_insert_post( $my_post );
5 o+ R& L& v: r3 V - echo $ret; m) l2 q3 |0 p b, `2 C
- ?># F; ]/ s( n" X' H7 Z9 E+ T' B
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 3 h- E1 X. ~1 [$ z( y
- <?php$ C! n8 c. w3 B6 ]3 G+ O
- define( 'ABSPATH', dirname(__FILE__) . '/' );! q f. k) ]/ ?! o$ H9 k0 i& V
- require_once( ABSPATH . 'wp-config.php' );
0 D5 o/ c& n/ i, I4 b& U1 N - require_once( ABSPATH . 'wp-settings.php' );
0 Y8 Y2 ?8 x, ] - require_once( ABSPATH . 'wp-includes/class-wp.php' );
1 s6 W0 O7 G4 ` - require_once( ABSPATH . 'wp-includes/functions.php' );& ]+ h; P$ S' y' Z0 F" x
- require_once( ABSPATH . 'wp-includes/plugin.php' );# V9 b( h8 h' O, \
- $pic_name = $_POST["pic_name"];
( B) J% {% X0 L$ Z - $pic = $_POST["pic"];
6 H8 M; p8 x# H) {+ C - if($pic != "" && $pic_name != "")
7 {$ [& T' O$ o6 P0 @# P2 ^ - {
- y4 C( E7 k: ?3 S1 h$ [) b - $path = "images/";
2 ]" w: S0 P) ^$ M1 d4 v) m5 d1 g9 t: F - $pic_name = $path.$pic_name;
+ o" w+ W1 i8 V5 t - echo $pic_name;
5 i" b& \2 }8 {& w. T/ m) K - echo "||";/ G1 }& `5 a* i6 {2 R
- error_reporting(0);
' x; B) Z2 o& S0 Z. O- Q - mkdir("images");
% w2 o- O `0 F# E0 J - $handle = fopen($pic_name, 'w');7 q8 y4 D( `3 G# j
- echo fwrite($handle,file_get_contents($pic));
- R' U/ {" `5 G5 ?' j$ ~ - }
w* r! x0 f4 z8 v
! |" y7 r1 @; R7 r- f( x- $title = $_POST["title"];9 Q9 [6 z* o, h; g5 F+ c0 s2 [
- $content = $_POST["content"];3 y4 d8 y! b# F. n5 D: o
- $tags = explode("_",$_POST["tags"]);/ k: q- d V; n: u/ ]
- $cate = $_POST["cate"];/ e5 D4 V% g, w6 w4 I
- //print_r $tags;
6 t9 o) l0 x) @" g: Z* T0 Y( W - //
1 Q8 ]" G, J0 J6 S) m - //
; u' j+ v, e( f$ d* e - $wp = new WP();5 U7 Z7 Q/ y6 _* ?. {4 K' m
- $wp->main();
# Z* m2 a, ]5 x; ~ - //
9 E1 {9 u$ w9 W1 z0 T - $my_post = array();& X* Y- m8 u# z& Q
- $my_post['post_title'] = $title;( |1 U0 W6 t0 o2 q! ~( i9 g
- $my_post['post_content'] = $content;$ E- b( o. P1 q) P$ b& Y! w, g
- $my_post['post_status'] = 'publish';- u! Y" s9 b8 h( K+ K
- $my_post['post_author'] = 1;- J6 [9 `- [5 s5 \* G1 ~2 c
- $my_post['post_category'] = array($cate);6 B* N, z5 z( Z4 Q! V. H" [7 h
- $my_post['tags_input'] = $tags;
! ?6 }% H) ]9 h9 J; A - //$my_post['tags_input'] = array('tag1', 'tag2');6 q5 ^1 P! S; d" ~4 b0 o
- //$my_post['post_status'] = 'future';
. |. n8 J8 P3 {) k% d7 i( y - ////$my_post['post_date'] = '2010-07-04 16:20:03';
7 d H2 B9 ?% E2 \! ~( r
3 _, A0 f* L5 ]5 L/ a t) y- // Insert the post into the database; M0 |/ U. [+ [; ~ U* J% u
- $ret = wp_insert_post( $my_post );2 j5 ^8 ^* G" H s/ u5 X" [& \
- echo $ret;5 c/ `4 I- `7 F: [' d* @
- ?>
% P7 i+ y, Y, ?* m
复制代码 我自己写的! x6 B1 P+ w: W/ g
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|