|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
) O o) ]3 }* d+ l; ]
3 c# q6 \! l) n& {直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
- K" ^5 @$ l( `4 c8 w7 D; |2 c1 I5 \* m, k S4 L% z8 ?
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
/ i; C& q, V; h- o$ F; ^% s. J* n% _8 V0 k$ y: G( i5 P; ~. r
方便实用 简单 何乐而不用呢- 2 r* k2 ~# G! l! l" z7 ?
- <?php
: t- E1 @5 Y1 a! I' T( U
& d2 p8 K* V0 M% B- define( 'ABSPATH', dirname(__FILE__) . '/' );" o9 T) A) ~1 G3 z; H5 @
- require_once( ABSPATH . 'wp-config.php' );
+ g2 e% ?1 G5 t4 Y W7 q - require_once( ABSPATH . 'wp-settings.php' );$ t" s/ L; A- {) h) E0 p4 j
- require_once( ABSPATH . 'wp-includes/class-wp.php' );1 M2 ^0 M) r, Q& u: }
- require_once( ABSPATH . 'wp-includes/functions.php' );
7 F- ^6 T1 ?: @$ U* X# U - require_once( ABSPATH . 'wp-includes/plugin.php' );" z0 Y* ?3 m5 M) E+ T% J8 m8 Y
- $title = $_POST["title"];
8 r& k7 M; O* K3 \ - $content = $_POST["content"];
! h+ R* D) h7 Y% I - $tags = explode("_",$_POST["tags"]);1 q) x9 K: j, l: K4 F
- $cate = $_POST["cate"];
' a% Q, |" D8 ^4 K' v9 { - //print_r $tags;
# P0 t7 p" U) D8 j - //
0 ^3 D( l6 j" e9 I' q* ? - //2 E! ]8 N6 H8 P
- $wp = new WP();; y& Z% a# s# x# @# P; \
- $wp->main();
4 l- R4 z' d4 Q; E) m& k - //
1 v4 ?3 v* l" e8 J9 z6 O& W w/ q - $my_post = array();/ _( v3 I" w9 |
- $my_post['post_title'] = $title;
8 |- k$ F# \1 j+ g, F0 `% n( t - $my_post['post_content'] = $content;
0 o) \* X% ?5 v: m8 X7 n - $my_post['post_status'] = 'publish';
8 V( X7 l1 E- O/ a( L - $my_post['post_author'] = 1;5 ?# [8 k, G [ {- B- {& Q
- $my_post['post_category'] = array($cate);
; k/ E2 x, s( k( t( v$ N - $my_post['tags_input'] = $tags;
7 {9 z( x" J9 f, U - //$my_post['tags_input'] = array('tag1', 'tag2');! c0 A4 R, L7 v1 R; W5 e+ r0 r
- //$my_post['post_status'] = 'future';# L0 e" D1 G( T% J- K1 i* f
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
+ p; }2 ]$ l3 B- O! q# ?6 P. E5 U
* J X$ K+ [# R4 t3 }- // Insert the post into the database
* ?- G \: ?; |* H) `+ W/ ^ - $ret = wp_insert_post( $my_post );/ i3 M3 g$ C" O7 E* z# \& U" j
- echo $ret;" {+ ] |/ r _* M0 r
- ?>
2 V) W$ P( f) D7 O
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
. _) b6 g8 J. h+ x5 N2 Z- <?php
' r; r, w( Y% p; G: z$ o9 m - define( 'ABSPATH', dirname(__FILE__) . '/' );# Q e0 ^0 h1 C* p
- require_once( ABSPATH . 'wp-config.php' );/ N: Y- ]2 k5 a! q& E! n
- require_once( ABSPATH . 'wp-settings.php' );" m& e8 L& ~( q, s1 j1 I, o7 K! Z
- require_once( ABSPATH . 'wp-includes/class-wp.php' );1 w- a2 Z3 J/ @6 B
- require_once( ABSPATH . 'wp-includes/functions.php' );
4 f* h- T" y1 k! s0 R7 c - require_once( ABSPATH . 'wp-includes/plugin.php' );/ R6 X, z- G8 j( I8 a- v* ^& x
- $pic_name = $_POST["pic_name"];
* Z! o$ V1 f: K" d% z0 w - $pic = $_POST["pic"];/ g( ]5 r$ S. P' g
- if($pic != "" && $pic_name != "")" n( ^6 {# \! s' m( r, F+ Z* F
- {
7 F! [2 h9 v0 t8 N6 u - $path = "images/";( b$ l$ \2 F$ c: i/ Q R
- $pic_name = $path.$pic_name;; \8 n G U) ?! R# [4 L* j4 J! L7 F
- echo $pic_name;# T1 C3 I; C. g( j+ ~7 B
- echo "||";
5 Y* @8 l8 ?& ]9 o* i3 f! }$ O* G - error_reporting(0);* f0 h7 W H+ N4 ?& j
- mkdir("images");5 Y2 C5 ~3 u* D; _, |; C
- $handle = fopen($pic_name, 'w');7 ?. f k! E5 p0 H% v
- echo fwrite($handle,file_get_contents($pic));
: h- s& S0 Q) C0 l" a4 F - }
; @. j( @8 |% s$ N6 f
# b8 b6 y5 I2 b \1 d- $title = $_POST["title"];
`2 S. h" V! m, u# L: ?" m - $content = $_POST["content"];
& _5 D9 H* B0 m- O8 L/ J. Q - $tags = explode("_",$_POST["tags"]);
- X) F# S( C. `; l! @' E8 a; Q - $cate = $_POST["cate"];
. Q6 r# L/ l( S1 U# j+ P9 P - //print_r $tags;
0 a) G2 Y8 U/ X4 e# @ - //; ^( l! ] p8 L# Q
- //+ `! b; a* @! ]
- $wp = new WP();
- ?' w1 o4 I0 w* `1 L - $wp->main();0 F3 t7 c+ o5 i
- //
5 _1 }. T/ b1 {# n8 B - $my_post = array();
2 v3 k9 y7 u+ ]8 z - $my_post['post_title'] = $title;" H4 @% @; _' b$ [
- $my_post['post_content'] = $content;
$ e) U/ O3 N, e& N1 S9 g - $my_post['post_status'] = 'publish';5 c$ A; q, Y2 d1 T% b8 S6 n, a/ ]' V
- $my_post['post_author'] = 1;
% }5 u* ^: j8 c9 h - $my_post['post_category'] = array($cate);
/ |# j# j; Z7 o& [2 { - $my_post['tags_input'] = $tags;
# f: e; p! r6 U - //$my_post['tags_input'] = array('tag1', 'tag2');
& v# e" i7 Q! u8 Z/ Z6 I - //$my_post['post_status'] = 'future';3 C1 Y' S9 B: ?8 e' s
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
. ~0 A( v' O) @, u% b% ]' X- y3 ` - ; \. ?" C+ Z" x& P
- // Insert the post into the database
& I1 E7 r. d* B - $ret = wp_insert_post( $my_post );! k% Y7 I6 p! _' j1 P
- echo $ret;
- g# ~ _$ C# ^- \) o" n* r - ?>5 I3 O" j9 {7 @* E( f
复制代码 我自己写的& H) o( m, j, j3 I; P
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|