|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
1 X$ w& A5 f/ \9 [; k
6 J! Z, {1 ]8 q0 G% V7 S直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
1 t* L8 m: e1 v9 o8 w! m; q
2 S% w- O" f: }3 I( _" r我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了* q J% } P q
/ M0 Q1 i E9 r2 e
方便实用 简单 何乐而不用呢
( M* Z4 R; B; Z) x- <?php
: E2 Y5 a; s& z( ]6 l$ b) n
/ e8 U/ N4 T' {5 S8 X# o% G- define( 'ABSPATH', dirname(__FILE__) . '/' );
: h0 k# w, a9 T9 q c2 ?4 V2 t - require_once( ABSPATH . 'wp-config.php' );/ J7 o9 B u6 L2 s, `+ }
- require_once( ABSPATH . 'wp-settings.php' );8 D+ j d5 _) |3 A
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
. m& x! Q C1 D - require_once( ABSPATH . 'wp-includes/functions.php' );% `. N1 g1 n1 X1 ?6 `3 y7 q
- require_once( ABSPATH . 'wp-includes/plugin.php' );
9 S' Z, y& T" Y9 D8 T- c - $title = $_POST["title"];) X2 P9 P- r" y5 g$ ]: a/ R# H. O3 o
- $content = $_POST["content"];
: Y. ?% ^1 b7 ^; ], I4 `- D' V - $tags = explode("_",$_POST["tags"]);
7 a0 q2 u. b3 ?* y$ A3 y: v - $cate = $_POST["cate"];8 m% k9 M8 E: O/ [- E$ A% K# B) {4 e
- //print_r $tags;
' \( A9 _' f9 x1 F+ j7 \. U5 W - //
8 e6 I8 w6 n/ |4 b: d - //
m7 W* X" M+ \8 i7 n$ J/ r3 g! [6 w3 i - $wp = new WP();
. f; Y% ~) I1 {0 E2 w3 s n) m - $wp->main();1 V# B7 A7 Q, m) g' A
- //, |* w* H F9 c( s0 p8 u
- $my_post = array();
! [- c# D7 x/ l/ w' A) S( F6 c - $my_post['post_title'] = $title;2 L. J6 g* E8 X8 X. _3 C A, E0 d
- $my_post['post_content'] = $content;
' q! b/ \! i- }' v - $my_post['post_status'] = 'publish';
/ I a L0 c8 @ - $my_post['post_author'] = 1;" E$ Y: M8 A5 W
- $my_post['post_category'] = array($cate);
9 |* X* x `0 J- P+ t - $my_post['tags_input'] = $tags; A2 ^ x/ z3 d7 J) D
- //$my_post['tags_input'] = array('tag1', 'tag2');
1 a: Z% R( w g, [' ]8 a - //$my_post['post_status'] = 'future';
' a$ t8 N L u9 v2 y6 f1 f - ////$my_post['post_date'] = '2010-07-04 16:20:03';
$ U7 P! ~7 _- S- f1 I, y8 G. M
( K" p) C- `3 D3 E9 X) h; e) r- // Insert the post into the database
6 V4 ]/ `( p- e6 S - $ret = wp_insert_post( $my_post );
7 Y. E4 q& v( r9 L1 q - echo $ret;
) E- _! y# K& Y8 b$ ]* }6 S - ?>7 Z4 O5 }7 r9 H! G! d# v* Q
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ; s: r- T3 Q6 {
- <?php9 M0 z( h0 G* l2 S% C2 l
- define( 'ABSPATH', dirname(__FILE__) . '/' );- Y! D$ I6 M/ P; K, `
- require_once( ABSPATH . 'wp-config.php' );& v$ d M k2 ]+ J
- require_once( ABSPATH . 'wp-settings.php' );
* x- w" `' ~* p( \" c - require_once( ABSPATH . 'wp-includes/class-wp.php' );
8 K. S. y( u/ Q; z: h$ t; z4 T( p - require_once( ABSPATH . 'wp-includes/functions.php' );
1 D& m2 p* N6 ^. U$ ] j/ [; \ - require_once( ABSPATH . 'wp-includes/plugin.php' );
( g' D1 {7 _, G8 { - $pic_name = $_POST["pic_name"];5 j% z& t4 x5 s6 J* O+ T
- $pic = $_POST["pic"];9 O6 }0 V, l2 I7 M6 y3 U6 n" I
- if($pic != "" && $pic_name != "")
: m3 K ?6 P8 ~7 P7 e5 @: V# k - {
. \& d9 ?. ^8 V( @2 p+ G - $path = "images/";
3 {* W4 ^, Q. t8 { - $pic_name = $path.$pic_name;
- K0 p" ?) J, [. Y) W - echo $pic_name;8 _" ^$ C0 d% U4 k) G9 p" e; L
- echo "||";/ j" q$ r/ t0 H, B8 n
- error_reporting(0);7 \6 ]) y1 o7 |+ ^; P
- mkdir("images");
% a$ ~, f6 M' @& [ - $handle = fopen($pic_name, 'w');
9 |* q! | }1 P/ T" d7 Y( }3 ^3 Z( D - echo fwrite($handle,file_get_contents($pic));
) M" [$ m5 i6 E# G( |+ F4 o - }
0 E% k, c4 P7 ?# h - 1 z6 g% d/ V; Y# A
- $title = $_POST["title"];% T: c4 g8 ^! Q+ _$ o
- $content = $_POST["content"];1 [# s+ B- d( W; V& ?+ K
- $tags = explode("_",$_POST["tags"]);5 }8 w4 U0 w; V# ~
- $cate = $_POST["cate"];* M+ A! d/ C" Q* P# u
- //print_r $tags;# v& s) o- j' m, \, b3 H( Y
- //
5 y+ g+ s3 g, O6 X( n( v ^9 t - //9 ^& b2 Y7 g4 c% e; k* g3 T6 `* C' x
- $wp = new WP();
% c, r' ^1 o r/ b% g5 o - $wp->main();
6 u+ Y, n* i9 H7 U6 X7 X( o - //, m0 [ f$ z8 k6 X
- $my_post = array();: \- D5 |9 B4 |# ~
- $my_post['post_title'] = $title;
/ [% x& B _9 v: t4 @4 r - $my_post['post_content'] = $content;
) x$ z0 k/ | Y& }; E0 E - $my_post['post_status'] = 'publish';
" b9 d" J5 n9 s; z- S - $my_post['post_author'] = 1;
! @4 a. H1 U# Q/ W5 C - $my_post['post_category'] = array($cate);
! l/ c. m0 H, H( V - $my_post['tags_input'] = $tags;+ E/ u! j0 i) b. Q1 p7 r4 E
- //$my_post['tags_input'] = array('tag1', 'tag2');
6 Z2 b0 [5 m) V% w Y/ R - //$my_post['post_status'] = 'future';
+ ]4 i# \% Z/ i( f+ | - ////$my_post['post_date'] = '2010-07-04 16:20:03';
6 B1 ^% y4 C* f$ b/ V - ( c2 j" Z3 c0 w' h0 ~; ^- W) K
- // Insert the post into the database0 \4 y t h4 ?* R/ {3 s
- $ret = wp_insert_post( $my_post );' c9 T: W+ H8 Z( z. n7 I- v4 P/ z
- echo $ret;
* V! X; n- `6 }; k, u3 b- c& o3 \ - ?>
1 H: A/ e, j ]
复制代码 我自己写的
# ^6 u/ X4 u2 c$ R9 C9 G插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|