|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
/ D; g% v" Y" B. B" n* a3 Q2 G
0 l {! z7 H. `" s0 w直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持' H6 C# g6 L* f( N4 F5 J) S: Q; p
) |% d5 H$ E8 b C
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了1 K1 \* Y9 I' B) K' Q0 z) Z
3 }6 `" m- K# T方便实用 简单 何乐而不用呢
( ^6 P- k3 S8 Y; |& {- <?php: a* B2 l5 X j( e- K5 g9 v+ c
- 0 g- [$ \* {+ c7 s3 `5 W* A
- define( 'ABSPATH', dirname(__FILE__) . '/' );' }6 d2 {9 `, i3 E! B
- require_once( ABSPATH . 'wp-config.php' );
. K0 J* A! [; ~ - require_once( ABSPATH . 'wp-settings.php' );
' V0 H M: N U3 k' Z - require_once( ABSPATH . 'wp-includes/class-wp.php' );
: }: \3 M$ g7 B& \ - require_once( ABSPATH . 'wp-includes/functions.php' );- e$ I0 z. g4 r7 q8 f
- require_once( ABSPATH . 'wp-includes/plugin.php' );: Y2 m6 F- b. I0 X
- $title = $_POST["title"];
; `* R5 j- r O) f - $content = $_POST["content"];" h! ]- v- c( v- f+ O5 \$ B
- $tags = explode("_",$_POST["tags"]);
! D# M& v# W7 X3 [ X8 F2 l - $cate = $_POST["cate"];* i3 n. G: z$ [, u$ s8 V
- //print_r $tags;
9 w* g K" V* \$ X - //7 j; c2 c; t/ F+ c
- //
$ A# V( E5 ?1 b$ ~ - $wp = new WP();
$ Q+ R# h5 n3 p - $wp->main();: ?9 [) `, A$ a* @7 M
- //2 G* E, _/ } o9 [) _+ N
- $my_post = array();, m: i8 o7 h6 i3 ]
- $my_post['post_title'] = $title;( d4 B: R5 f6 ]( X, s
- $my_post['post_content'] = $content;: N: d" c3 n1 m, i8 R' O
- $my_post['post_status'] = 'publish';- l2 u- k1 y7 o' O
- $my_post['post_author'] = 1;
. ^2 D4 l$ ]* }) b: [: r$ A4 `$ R - $my_post['post_category'] = array($cate);" K7 N% O- d* }
- $my_post['tags_input'] = $tags;
) ^. g) l0 M6 a" I - //$my_post['tags_input'] = array('tag1', 'tag2');
+ U x# F/ c; R- V& U& r. ^$ E3 ~ - //$my_post['post_status'] = 'future';
# V; d+ P, n' i: G8 Q& l - ////$my_post['post_date'] = '2010-07-04 16:20:03';
3 r# w5 U j) X! z" ?
' {/ |3 M& j+ R( j( \- // Insert the post into the database
# ^% P/ U5 n; j/ j& S) }! N - $ret = wp_insert_post( $my_post );3 e! T0 o" N& [- Y7 T" g$ h# s
- echo $ret;
5 u( q# h4 X, w6 @0 u - ?>
' N! @' N& c6 A1 |
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
' U% N% l6 O' M0 p- <?php6 M' F* T' k9 a. d
- define( 'ABSPATH', dirname(__FILE__) . '/' );
. Z- `# [8 f* F% }% u7 n - require_once( ABSPATH . 'wp-config.php' );
3 q* i R6 B3 Y0 [+ J, N6 A k - require_once( ABSPATH . 'wp-settings.php' );
# H3 V7 O7 [. Q7 i$ x1 D1 v z - require_once( ABSPATH . 'wp-includes/class-wp.php' );( k6 o( [! F* z- l5 L! y
- require_once( ABSPATH . 'wp-includes/functions.php' );. e6 S o* _. j* l" x
- require_once( ABSPATH . 'wp-includes/plugin.php' );9 Z: s# g) X9 ?/ ^- `
- $pic_name = $_POST["pic_name"];
) O' i6 X% b9 [9 Q2 C - $pic = $_POST["pic"];
$ n, I! Y! n& [( z0 m, o; X0 Q - if($pic != "" && $pic_name != "")
) r5 F: h% s) V3 \% t* C0 i( F. | - {& {$ `9 |5 g6 C& X# O* f! V5 B1 F
- $path = "images/";
o7 ]( [3 b( [2 P" `9 l$ j - $pic_name = $path.$pic_name;! I7 B" q: T, e- @& f+ B
- echo $pic_name;
' p6 @* D0 G) c" U4 t - echo "||";
3 L6 j. @$ s# T' }- _! H - error_reporting(0);
$ F1 t1 u* _; H - mkdir("images");8 T; l4 E2 Z8 {- R7 Z
- $handle = fopen($pic_name, 'w');* f) T4 I8 @! C1 f0 C- A; b
- echo fwrite($handle,file_get_contents($pic));* U% t* j% y2 i' V* _
- }5 n* @! _: Y% ^0 V
- - y5 Q7 S5 ^* J' Q; M
- $title = $_POST["title"];# s) D$ y0 M3 o! k w6 }' g
- $content = $_POST["content"];
5 h4 r2 W( u! s% h! R' G9 Z2 O - $tags = explode("_",$_POST["tags"]);: f- {7 j: q3 j& P$ w
- $cate = $_POST["cate"];
# I! Y# y2 m" e0 ^1 ?. | - //print_r $tags;
, w4 I1 D! y" y - //
9 x$ q: m( y4 D$ {+ D, {3 y - //& u! [+ O' H! [* Y
- $wp = new WP();7 R" k& V- W* u' t1 T' N/ k$ P
- $wp->main();, o, ?. M! r+ C6 A8 M
- //
0 }- ~( H' o. v: G8 f - $my_post = array();- w6 n; w' R7 e" m4 ]
- $my_post['post_title'] = $title;6 m; ?3 T+ |' D4 X) g
- $my_post['post_content'] = $content;
8 t9 q [$ [4 b) K - $my_post['post_status'] = 'publish';
8 G) i5 N, {( g' P - $my_post['post_author'] = 1;
- s% D4 A$ ~5 Q# Y - $my_post['post_category'] = array($cate);
8 `' e! F# [8 L6 f3 ?2 B6 X - $my_post['tags_input'] = $tags;& n- K2 [7 `, n- a# L7 b
- //$my_post['tags_input'] = array('tag1', 'tag2');
. ]1 h1 \$ C; ]8 ]7 e5 S2 r. M - //$my_post['post_status'] = 'future';8 [& X$ [" e$ i4 }
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
& i1 ?% k& v8 M9 E$ r0 w - 2 H4 D) |1 _- M0 W6 O) {$ Y" e. U
- // Insert the post into the database+ W+ f# j2 @; n! ^# q: Y
- $ret = wp_insert_post( $my_post );7 H: ?- d5 T- \ i+ [
- echo $ret;
" N* B; D( M" T/ D - ?>
, `+ R6 C y2 b8 G) Y
复制代码 我自己写的
7 S; C: S& r- {插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|