|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 1 `! G% f* ?7 e2 N. S
7 v' c& M( ^& a; z0 W2 Z# |
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
+ h6 [- Z2 K) O1 M2 x( V5 X9 j0 F2 j& Z
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了5 V2 {1 p. l/ g: x
& r, E/ Z4 h: A" r* `$ S: g. t. i
方便实用 简单 何乐而不用呢- ' \$ \6 _) m% S% u9 a
- <?php0 E! Q& L3 T) E- a
- , Z( l1 `8 G4 l' P+ g; y
- define( 'ABSPATH', dirname(__FILE__) . '/' );! @0 e( D0 O' ^9 C9 T) s4 q
- require_once( ABSPATH . 'wp-config.php' );; Z* F5 L6 a9 B( c# h9 e
- require_once( ABSPATH . 'wp-settings.php' );. g4 L4 Z6 e( o- @
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
: O) F, J1 A, M* d9 y0 \: H - require_once( ABSPATH . 'wp-includes/functions.php' );5 t3 Q& B$ a8 b/ V
- require_once( ABSPATH . 'wp-includes/plugin.php' ); J3 w6 U5 F8 G2 a( N
- $title = $_POST["title"];
1 y, F) Y- B' p" t - $content = $_POST["content"];
. X+ k0 [: ]/ { - $tags = explode("_",$_POST["tags"]);
# Y( Q8 ?4 k8 N% o4 a/ _ - $cate = $_POST["cate"];
/ W; }* x ]* P- F - //print_r $tags;+ ^" Z5 q1 B4 `0 `" e: I
- //
" h5 I7 f5 X8 L9 Z! E - //
- Z) k: R6 A% ?1 S j( j; g - $wp = new WP();: z0 q* ?# v) Y# |& O+ V7 r" I
- $wp->main();
, Q2 u% p5 P' w* F4 V1 N8 R f - //$ D- X" Z4 R1 S9 D7 ]' L/ S9 j4 c
- $my_post = array();
# t6 K, D# P# Y( p/ E - $my_post['post_title'] = $title;7 ~% ^1 {6 e G4 K5 c6 `2 E
- $my_post['post_content'] = $content;# r2 U. ]6 o! l# P* Y& F1 |
- $my_post['post_status'] = 'publish';
2 t# H# g' g% f# v9 g - $my_post['post_author'] = 1;
6 y$ @7 r6 z" H! L; E) {2 }0 } - $my_post['post_category'] = array($cate);9 Q S- T: \# c3 G. f
- $my_post['tags_input'] = $tags;" ?7 J1 ]* n- h4 r
- //$my_post['tags_input'] = array('tag1', 'tag2');3 m+ c. ~! K% D1 A
- //$my_post['post_status'] = 'future';
3 I6 ~ M1 `5 x, Q6 f# l5 O4 b - ////$my_post['post_date'] = '2010-07-04 16:20:03';
5 P" q0 u/ _0 F7 V3 }7 G% Z5 i" C
! @. ?& C7 M- G& u; b; R ~& ?- // Insert the post into the database
) N. R i% v& T: e+ K - $ret = wp_insert_post( $my_post );
) w1 M0 `* d/ {9 y6 L- A - echo $ret;. G/ a- O6 f! }# d/ h3 T& J0 r
- ?>3 j- `, w3 _* U/ ~, M
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
9 x* E1 b$ }& K& |1 J+ ?' d5 H- <?php
) l4 Z% i% T' `( n - define( 'ABSPATH', dirname(__FILE__) . '/' );! ?9 d$ N& W5 D \. D1 ?
- require_once( ABSPATH . 'wp-config.php' );
' f, a/ Y8 G0 g. E. s5 D - require_once( ABSPATH . 'wp-settings.php' );/ P& Q- r8 ?9 G \. N
- require_once( ABSPATH . 'wp-includes/class-wp.php' );0 t; Q. {$ G; Q) A1 K& n
- require_once( ABSPATH . 'wp-includes/functions.php' );
r. }6 i0 i J. r) V$ y - require_once( ABSPATH . 'wp-includes/plugin.php' );8 m9 a; G i% t
- $pic_name = $_POST["pic_name"];5 Y f0 @7 {9 B- L( @! b( p* |$ V5 q
- $pic = $_POST["pic"]; o$ f% f x/ i7 ?0 o# H/ k- ~: d8 @
- if($pic != "" && $pic_name != "")
. {; U( B% I1 d: L - {" F0 d) q, C5 H$ v5 V% H, t( l
- $path = "images/";. w" X, X1 c, Q# j7 `( y
- $pic_name = $path.$pic_name;
5 u j W9 F% c/ X0 v4 r7 D9 }% m - echo $pic_name;
9 h: |+ L8 T' O1 \2 J; ?4 J4 Q - echo "||";( o& Q4 s! k: {% g% F
- error_reporting(0);0 C+ Z9 x6 C( H$ d6 _9 p
- mkdir("images");5 T/ x. l( W/ T5 E
- $handle = fopen($pic_name, 'w');, b( i Q- B3 `5 [0 |5 g
- echo fwrite($handle,file_get_contents($pic));
9 F1 [* [ B4 u( u. n+ L# ^/ ?. D* `# x - }3 x n3 ]4 y: {- x0 p- B- F
- $ U# U! R* V2 _ u9 g/ J: C1 b6 I
- $title = $_POST["title"];& ]5 Y$ {& x' } T' r" O
- $content = $_POST["content"];1 Z/ s# l1 [/ Y, ?. r" b8 a' s) {
- $tags = explode("_",$_POST["tags"]);' s1 W1 I. s8 p6 E
- $cate = $_POST["cate"];
' g& H& H" \9 O/ e - //print_r $tags;
# s1 T3 w3 @8 r0 R7 J, A# h, `- v - //
8 w8 z' D' _5 W7 u4 c - //
/ b8 ?1 |6 T5 U# w - $wp = new WP();
. b9 }/ A2 G E - $wp->main();" S; u8 f/ U2 a9 _$ E3 `
- /// u1 E d4 Q' S% k
- $my_post = array();
- e) ~9 P1 s( j% o: }& u - $my_post['post_title'] = $title;* L) X* a! J4 Z! g/ n
- $my_post['post_content'] = $content;' @1 D7 R6 M- B, q8 o
- $my_post['post_status'] = 'publish';" g& W! X# H2 b& P
- $my_post['post_author'] = 1;' y* e+ D" F- V; a7 a& f
- $my_post['post_category'] = array($cate);, l+ D; |' e1 p# w- J
- $my_post['tags_input'] = $tags;/ b/ t4 ^1 }" h
- //$my_post['tags_input'] = array('tag1', 'tag2');
* i; j* h! K" {0 r% e1 K - //$my_post['post_status'] = 'future';
8 h' B2 T0 b1 [/ T3 B: K/ g - ////$my_post['post_date'] = '2010-07-04 16:20:03';8 w6 M. z1 X8 \
9 h4 X+ m$ z' K* f* V# x- // Insert the post into the database
9 @" j% F v' Y5 z3 W- z - $ret = wp_insert_post( $my_post );
2 L2 Z2 o# _ Y1 u5 K3 b. _7 n - echo $ret;
% o8 O# U h( k, |4 Z: X& ? - ?>! t4 u2 o" ]% X; h' ?
复制代码 我自己写的
& C, n% |4 n/ R/ I- G2 y插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|