|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
- L7 q3 M3 P, J8 a: G- X* @$ R' n7 L. q
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持: B) n8 I4 k, K- c# V) W
' s* n5 x0 m6 P: y我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
9 D$ a" [* J5 J( \% o; H
( i+ }, r3 ]1 U& W+ A方便实用 简单 何乐而不用呢- / l* V2 t$ X$ a+ ~2 L% l
- <?php! T- o. f7 V+ c1 ~- P
) ^& T9 m- Z* a5 a! Y. l- define( 'ABSPATH', dirname(__FILE__) . '/' );
; g. b6 V$ r' _& {1 l5 _) n$ g - require_once( ABSPATH . 'wp-config.php' );
4 X& @3 v) e- @* p# }" r - require_once( ABSPATH . 'wp-settings.php' );: y/ s. K' T0 d+ V$ `( o3 U$ A% k
- require_once( ABSPATH . 'wp-includes/class-wp.php' );7 }0 `6 m! D( b* T
- require_once( ABSPATH . 'wp-includes/functions.php' );. ]% e4 _& u* n
- require_once( ABSPATH . 'wp-includes/plugin.php' );/ `( |" K9 j' v, N6 U, i2 |% I
- $title = $_POST["title"];( o6 r% ^9 o& v6 C8 j
- $content = $_POST["content"];) x( u: ^9 L1 B. b! f4 E
- $tags = explode("_",$_POST["tags"]);
2 J+ d1 g7 S1 U# S! } - $cate = $_POST["cate"];3 B' m, t; d+ Z
- //print_r $tags;& u) U* ]; a* o) x! L% ?
- //' Q% M, P# L9 P' ^
- //
j6 G) k& {; \- V c& r' O - $wp = new WP();4 z4 R* e# l8 L: ]( q: \1 z2 t
- $wp->main();
: Z- T# p7 N! u& X - //
! V0 o6 `( ^4 y3 t/ \ - $my_post = array();
% T3 Q. @ n5 ^* Z8 J5 w. X - $my_post['post_title'] = $title;
: ]. m) I! u7 n - $my_post['post_content'] = $content;
4 V- Q6 W4 ?# U4 O9 u) o2 y, y - $my_post['post_status'] = 'publish';
$ |( u7 J8 G, N! [. c; h: o, D - $my_post['post_author'] = 1;
6 I3 o( L7 j) C R3 @ - $my_post['post_category'] = array($cate);+ o+ i* p d7 C8 \/ a" ]" J
- $my_post['tags_input'] = $tags;
% w5 U+ _. c l6 h6 Z: g7 d( Q* J - //$my_post['tags_input'] = array('tag1', 'tag2');9 D+ x/ q2 v, |; l. E6 o0 Y/ N0 u
- //$my_post['post_status'] = 'future';
+ f# ~, g4 ]" U: K3 s( W; j - ////$my_post['post_date'] = '2010-07-04 16:20:03';" V* \9 L( Z# c5 \; q; ~8 `' W0 Z" G
: o$ n1 E$ y- k; y: H; j- // Insert the post into the database
8 l7 B) M8 v, [ G3 w- l3 ~ - $ret = wp_insert_post( $my_post );$ {4 `( T$ Y" o1 h2 X1 w ~' a
- echo $ret;8 g8 t+ W, @. b: L+ f
- ?>
. y5 R# H, Z% w7 Y
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
4 h1 p; @( }% r; s- <?php
% c3 F' s* U2 W6 ~6 M- {/ W4 Q - define( 'ABSPATH', dirname(__FILE__) . '/' );" T0 w8 ^) c4 ~: ?+ C4 \. B
- require_once( ABSPATH . 'wp-config.php' );9 h4 f+ {8 ?8 f8 s) |% K3 h( V% n+ T
- require_once( ABSPATH . 'wp-settings.php' );: C* j, N; F$ F+ h1 o, c N
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
; H( f7 X, t D$ o" r- m - require_once( ABSPATH . 'wp-includes/functions.php' );
0 n) c# t( _# H' p: R! }' O; f: B - require_once( ABSPATH . 'wp-includes/plugin.php' );7 J I& v* X6 @( g
- $pic_name = $_POST["pic_name"];' s' Z% z/ [5 N4 h K, C. J
- $pic = $_POST["pic"];
- h; r. ~) B7 s# C; H$ n# W+ u5 F - if($pic != "" && $pic_name != "")" u5 c7 M; |2 r& i8 ?
- {
' N1 ]% R$ U- k$ `# p5 @ - $path = "images/";9 c, c1 m9 j+ Q' P, y2 T6 a
- $pic_name = $path.$pic_name;
/ S) B+ ?2 O8 G7 B( } - echo $pic_name;
% ]6 D% @8 G0 h5 | - echo "||";
. E+ c9 O+ ~8 r, C5 m - error_reporting(0); _4 l+ u9 F! l! J3 a
- mkdir("images");. e; S: q' U& f. p
- $handle = fopen($pic_name, 'w');
$ l2 G6 `8 g6 }5 ]5 k6 T3 c/ K - echo fwrite($handle,file_get_contents($pic));
7 \! x7 @8 C8 L, X* D e |2 j - }( m C) }3 e ?& S7 v
, F3 @$ t1 }9 h* q- $title = $_POST["title"];7 L6 k4 V. u7 `& a; y9 d
- $content = $_POST["content"];
9 t/ L& T4 c- g& d% H; K5 g - $tags = explode("_",$_POST["tags"]);3 F/ O& s# @ @
- $cate = $_POST["cate"];( M0 o4 g1 O5 P% P" }0 w
- //print_r $tags;5 F$ |: g+ [3 K) I" u
- //. o' U& H4 V' k; Z
- //# I, C. x3 U o: B# ~# E2 q0 R1 K
- $wp = new WP();! F1 O4 l1 B* D2 |% J/ ]( p
- $wp->main();4 A: G9 W8 [) t# B# G- v& [
- //+ ]2 F1 Y! ] B& `8 D
- $my_post = array();
" t* N% K4 m( A& o; c+ B' x - $my_post['post_title'] = $title;" Z- ^) I2 r& P2 i3 @
- $my_post['post_content'] = $content;
+ V: `4 m" y+ U/ O+ k* S) A - $my_post['post_status'] = 'publish';3 |5 X; j0 U. p% r
- $my_post['post_author'] = 1;2 h! K. q. d; f* m. i& j, T
- $my_post['post_category'] = array($cate);
* _0 D+ {1 e' g$ a/ I - $my_post['tags_input'] = $tags;
8 E" v4 @' N' g: N# }) p; o8 ], v - //$my_post['tags_input'] = array('tag1', 'tag2');
2 {2 m1 `& Z3 H- g+ b( Z8 ~ - //$my_post['post_status'] = 'future';
1 _" M; {5 u) E" ~+ r9 C; L - ////$my_post['post_date'] = '2010-07-04 16:20:03';
) F4 \* @( p0 a0 @) X
( M( }5 x1 S; [' d5 B. e- // Insert the post into the database
& l. g0 U4 {- W! x; V% ^ w - $ret = wp_insert_post( $my_post );1 ^2 v6 Z# K, g: w! Z5 v
- echo $ret;) l3 i5 j/ ]& Z, b
- ?>; r; K% @8 Q/ a4 Y& ]7 P
复制代码 我自己写的0 q) z8 R! }: i3 U& a9 w/ H
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|