|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
' U- X( V; K8 c% m
# ~) q- u8 o& {8 _1 U6 J6 [; q直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
9 F' g; u4 K L
4 @; [7 e7 G. `% a我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
0 Y! Y$ v M8 o( \" N2 J+ T! |9 ~% L8 W& ~. V5 D% f' K% j& h
方便实用 简单 何乐而不用呢- * M1 ?' H1 j `, @- Q0 c% X
- <?php3 x+ {; ~; e I# F. W; w
# }. k* a R( {( J' Q {- define( 'ABSPATH', dirname(__FILE__) . '/' );
, a6 h( K8 V# C - require_once( ABSPATH . 'wp-config.php' );
1 R% n K" P6 F1 B" {( r% B5 V8 z - require_once( ABSPATH . 'wp-settings.php' );
3 l, f5 d. C' @9 I# k, \8 _- Q$ Q - require_once( ABSPATH . 'wp-includes/class-wp.php' );$ |3 M& p' O% a9 W, Z0 G& V
- require_once( ABSPATH . 'wp-includes/functions.php' );/ R- w! p0 A: B4 A2 _
- require_once( ABSPATH . 'wp-includes/plugin.php' );
$ ~( w' f h: W - $title = $_POST["title"];, z2 \4 N) S/ H' W5 f
- $content = $_POST["content"];
& ?! A M& s/ \+ I3 X! @, d: w- t - $tags = explode("_",$_POST["tags"]);
( M% ~9 Y: e7 G3 ^ - $cate = $_POST["cate"];/ W4 Y, U0 T: O+ z8 `
- //print_r $tags;: T! L. a# b5 d# E6 l. ^+ x" _
- //
5 W+ t$ l& j+ H* h: y - //
3 q0 I0 e! i @6 z - $wp = new WP();: X: u4 s" u* E, y
- $wp->main();
8 S, V' V4 h" q& `5 J2 F - //4 K$ ~: z3 ?) L7 s9 P1 w! B& q0 |
- $my_post = array();1 u" Z. @! v3 y
- $my_post['post_title'] = $title;( Z+ y0 e* M# `4 p- u) l
- $my_post['post_content'] = $content;
. y- e! e9 t. z6 }; R4 T - $my_post['post_status'] = 'publish';+ I4 |! P9 K. ]- L3 f; Y4 }2 \
- $my_post['post_author'] = 1;, o% u& y$ N2 w+ W
- $my_post['post_category'] = array($cate);) `1 |/ H/ @& H1 K
- $my_post['tags_input'] = $tags;4 \. u" y% ]/ V' @; h% t
- //$my_post['tags_input'] = array('tag1', 'tag2');0 X) b1 h: P4 I. B, y
- //$my_post['post_status'] = 'future';; z3 Z, D: o8 P6 W& x
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
8 k `1 I! R1 n- i u
0 j% ?+ o3 ~. @- // Insert the post into the database
) P- R) c" v4 H% M0 { - $ret = wp_insert_post( $my_post );( i& k' Q* w F3 O( |! L
- echo $ret;$ }9 [7 Y; J; p
- ?>: Z( o! O9 R, u% I
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
1 \/ {7 p1 A/ M, t$ d/ v- <?php) a' Z, S( k+ V6 t4 ] n" C, m
- define( 'ABSPATH', dirname(__FILE__) . '/' );
) p9 O w2 D: T# _9 b - require_once( ABSPATH . 'wp-config.php' );
" n8 C+ q* R* @6 P( V- y5 _4 f - require_once( ABSPATH . 'wp-settings.php' );2 r- R$ O/ i4 V9 O" R
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
; P u& z7 y9 q$ B8 ]7 Z - require_once( ABSPATH . 'wp-includes/functions.php' );; \+ u& s D- {. w; a5 a% }; U
- require_once( ABSPATH . 'wp-includes/plugin.php' );
$ M% v- B1 l3 c3 ~ - $pic_name = $_POST["pic_name"];: O) U# J$ G* @& N
- $pic = $_POST["pic"];
+ U/ Z; b: i$ }6 t6 f& ^7 } - if($pic != "" && $pic_name != "")
# @, ~+ Q9 ^/ _" i - {
% d" N0 g: q2 I L - $path = "images/";
5 z) @8 C X0 i: }( B7 V - $pic_name = $path.$pic_name;
$ P0 U; s$ L9 v7 `( P7 P - echo $pic_name;
$ F" E: I# _+ D( L - echo "||";
4 j2 A8 x i$ N - error_reporting(0);5 t, Q% n! V: I! Z$ K$ I
- mkdir("images");2 {" T4 \0 S: }- x# F4 F7 B
- $handle = fopen($pic_name, 'w');
' D- X, \5 o: k* q8 i2 y$ U - echo fwrite($handle,file_get_contents($pic));
, r: ?3 t9 @5 n8 z# o - }
+ T3 S' ~. y# ?& \# X1 ?4 G - ' W) @2 k( P8 |. k3 d, T
- $title = $_POST["title"];
5 m6 B T' b- D; B' ~$ @ - $content = $_POST["content"];- F) \8 j" ]# b" n, _0 e* K
- $tags = explode("_",$_POST["tags"]);) ]- K6 W; K) J/ [7 q
- $cate = $_POST["cate"];
1 l7 K- I: t' F8 {& R& B* d - //print_r $tags; D3 |$ ?- o9 i1 e
- //$ ?6 Z1 O2 `& z% c. J
- //
M9 Q' x) v! d$ ^ - $wp = new WP();" x: e1 h1 M7 m; {+ a
- $wp->main();( Q" _# l: ~# Z1 M' Q$ ]
- //( U Z4 S! ~ T- _0 B# _2 q
- $my_post = array();
, r6 \! A' i. e0 l% E& a: {" _. n - $my_post['post_title'] = $title;" c9 O5 @! B/ B, k# r% l& }
- $my_post['post_content'] = $content;
# l; R! H: e3 O8 Q8 ~7 ~" N2 d: m - $my_post['post_status'] = 'publish';8 @- `' c& t" H8 T6 e, P' z7 W, G
- $my_post['post_author'] = 1;
: v# R/ G( _& P1 y# m - $my_post['post_category'] = array($cate);1 H/ _0 B1 K' n9 o) Q u) v" b2 k; `* l
- $my_post['tags_input'] = $tags;5 o1 `* H- V( F( m- e
- //$my_post['tags_input'] = array('tag1', 'tag2'); ]3 s* B3 S& F! D1 G9 t
- //$my_post['post_status'] = 'future';
8 m! X/ |" z: I; j- ?4 f/ I2 p- g+ j8 m. U - ////$my_post['post_date'] = '2010-07-04 16:20:03';/ _# P8 ]( c, Y- Z0 y5 H& |
5 ~4 v+ T. {' Y, Q- // Insert the post into the database
3 r& Z9 r! k7 n1 n* w' o+ m5 h: i - $ret = wp_insert_post( $my_post );
5 _. @# @% R5 ^1 _5 v2 t - echo $ret;
2 T/ U+ u7 ^2 W) I8 J - ?>7 ]; l1 z c1 ^+ p8 n* U
复制代码 我自己写的7 t# _" C: h \8 k
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|