|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
8 U/ J( t, A& T" ^" h( C7 w6 R- A; Y* U
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持! O5 V6 E& g) J& b0 l
2 ^, E1 g( t; M% Z" |' x% ?4 @
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了- q# x# ?. M5 f; j% ~4 d
% _6 R" i" J; ]0 C9 ^$ D0 Z方便实用 简单 何乐而不用呢- 3 l% T, W4 h' A, @3 }
- <?php
7 c; n' l3 I- c) Z3 Q - 3 z- P# V5 | v: _7 X
- define( 'ABSPATH', dirname(__FILE__) . '/' );! y% R, r4 G- L% N6 I" N
- require_once( ABSPATH . 'wp-config.php' );; x0 H. {* u* g* P1 }
- require_once( ABSPATH . 'wp-settings.php' );
) z3 y% A; [) H1 b - require_once( ABSPATH . 'wp-includes/class-wp.php' );
9 \! h+ w- Y: q0 ~' z: E - require_once( ABSPATH . 'wp-includes/functions.php' );
% J5 e# b9 g, V! b: M! t - require_once( ABSPATH . 'wp-includes/plugin.php' );: l, W4 ?& O G/ n0 z. Z; i
- $title = $_POST["title"];& S9 X# F% I6 M- X- n% d
- $content = $_POST["content"];
- \) d [6 w0 I, ]8 w - $tags = explode("_",$_POST["tags"]);
# \6 N2 f& z2 z4 S. j3 {$ V& X - $cate = $_POST["cate"];
/ C- i q: u$ U t w' d0 c - //print_r $tags;
& ?7 Y+ M5 ^* K# t1 t1 m0 @ - //
/ V2 e& r) \) R* R" f7 x - //. b2 k; _" E( b* h, V
- $wp = new WP();% f- Z, i: v) A2 u/ i
- $wp->main();' Q* L& V9 I0 u4 j
- //& l+ Y: E, l, ^
- $my_post = array();
( n6 |( c2 Y0 T - $my_post['post_title'] = $title;
7 y6 w9 F% C/ a8 K - $my_post['post_content'] = $content;
& q* ?, l9 f% ?) b& ]8 a5 n9 L - $my_post['post_status'] = 'publish';
) a* n' V! Z( }7 D$ | - $my_post['post_author'] = 1;
4 s3 a9 J0 b* K4 m- @. J7 T: \ - $my_post['post_category'] = array($cate);
) }6 S' D( A r$ K - $my_post['tags_input'] = $tags;
' h5 P T: g: H9 M y - //$my_post['tags_input'] = array('tag1', 'tag2');2 i; H: a5 J1 {
- //$my_post['post_status'] = 'future';
1 X y8 W M3 A - ////$my_post['post_date'] = '2010-07-04 16:20:03';
' l) @. N- x! b% \. j. ~ - # f* `8 z0 V0 t- S$ {0 o
- // Insert the post into the database7 r8 j4 L A$ d: l( W2 y# q
- $ret = wp_insert_post( $my_post );
1 b1 _' d& q* L - echo $ret;
: i! b/ C) N6 q - ?>
+ e! W* T7 S. N8 `: b5 I) P
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
6 \" p1 J+ j$ G" q @ C. ?- <?php9 i% l6 }+ G8 }9 w
- define( 'ABSPATH', dirname(__FILE__) . '/' );3 P: {" u3 Z9 d* g8 l2 E
- require_once( ABSPATH . 'wp-config.php' );
& Z5 J3 n& }: f: b - require_once( ABSPATH . 'wp-settings.php' );
' \% z" m' u r4 w - require_once( ABSPATH . 'wp-includes/class-wp.php' );
3 G# t. A6 X4 V7 p* ]7 g - require_once( ABSPATH . 'wp-includes/functions.php' );
2 w9 h/ i+ y; G3 t3 I - require_once( ABSPATH . 'wp-includes/plugin.php' );
' m( W2 w9 _) X% X, i4 E0 E - $pic_name = $_POST["pic_name"];9 B/ @" j% D, k j7 A" f8 a
- $pic = $_POST["pic"];
% @9 m8 j2 l7 _) L5 P, i - if($pic != "" && $pic_name != "")
; v% H; E. y# X5 e - {* ]. Q5 {- K4 Y
- $path = "images/";1 g' y: t3 q0 K* h8 b: X
- $pic_name = $path.$pic_name;
9 N. p B+ ?% p2 S7 N. r+ G - echo $pic_name;
/ k* p. L0 o2 D - echo "||";4 E5 `4 \8 s. ]3 _0 E
- error_reporting(0);
% H; v: Y% u+ B- X$ A2 f3 G! }6 x - mkdir("images");
. s5 i+ k$ G/ m& f% H - $handle = fopen($pic_name, 'w');
* a( O5 u9 q! s# O" C0 @& Q - echo fwrite($handle,file_get_contents($pic));" c+ S' H% D7 G3 h
- }; ] r6 M9 T. j/ x/ [7 Z% D8 L
- ! O( |0 c6 \. h
- $title = $_POST["title"];
5 k+ O% @3 |0 S9 W5 H5 `# | - $content = $_POST["content"];* r2 o/ Q7 g7 A3 z
- $tags = explode("_",$_POST["tags"]);7 v: X/ j J# |: o3 x# Y. M
- $cate = $_POST["cate"];
, C+ p/ G6 k( e0 g - //print_r $tags;* o o- e) U6 N" U3 c3 I. ^1 k
- //
' y) _% ~- d+ g+ a: i% Q - //# w, v' k* a( q6 a. D; p" `/ Z
- $wp = new WP();
9 r4 F4 T! Q W+ d* A2 P6 C6 Z - $wp->main();0 R0 `) ?- i: z$ [
- // h, O1 i5 H+ |
- $my_post = array();7 [, T) z! `3 b6 T3 I: n" p
- $my_post['post_title'] = $title;* |( Z1 \! o% L' X' Q
- $my_post['post_content'] = $content;
# n# S7 X0 m; i V9 x u3 V - $my_post['post_status'] = 'publish';
1 L3 }8 E& [& x5 I, }1 ?* J - $my_post['post_author'] = 1;
8 L3 }5 T( N7 t' X2 o( i2 ^2 J - $my_post['post_category'] = array($cate);5 h* a* y6 a R2 n
- $my_post['tags_input'] = $tags;6 B: a* r7 s( }' A3 b7 B
- //$my_post['tags_input'] = array('tag1', 'tag2');2 q: f; A3 _4 w0 m
- //$my_post['post_status'] = 'future';
5 a5 q; D2 |" e; q4 g - ////$my_post['post_date'] = '2010-07-04 16:20:03';
/ l6 u9 A6 M( X- `% }1 C: n, U5 o9 |
( A) b/ p0 y* a1 M4 b- // Insert the post into the database& n0 n7 c& Y2 G. \8 s) _6 y
- $ret = wp_insert_post( $my_post );' d m& a7 b* Q5 x
- echo $ret;
9 I8 T4 d, N! a7 l) | - ?>+ j: ?. Q1 F8 D2 ]! e
复制代码 我自己写的( u" C/ y$ m: G0 S' h d# H& I
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|