|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 / B5 \ v2 I. T3 ^, k: c5 W* k1 L. u
$ W) L$ t# G4 x+ p
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持" V8 p4 t1 `7 D4 R" C
- d& I! L: ~( |( k/ _8 }* u+ l我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
' \2 D' I) J! o" T" H8 z" g' H& w9 P' l7 \+ \7 I& P1 g' O- `
方便实用 简单 何乐而不用呢
! C8 v y' [1 A9 a6 `+ u- <?php8 H8 Y% K0 y" ]+ G
- ( f. p% r& x; n- c5 q1 {4 z
- define( 'ABSPATH', dirname(__FILE__) . '/' );
$ H. O+ G4 E* [! Q1 |+ G/ @8 y: I - require_once( ABSPATH . 'wp-config.php' );
6 t& ~' ^6 {; z4 k/ e3 m5 z - require_once( ABSPATH . 'wp-settings.php' );
# i4 ^3 V; P. R5 o - require_once( ABSPATH . 'wp-includes/class-wp.php' );$ c9 _5 v% {- ^# n
- require_once( ABSPATH . 'wp-includes/functions.php' );9 e2 H# @$ w+ b( o( K
- require_once( ABSPATH . 'wp-includes/plugin.php' );3 ]1 u) q. Z: j
- $title = $_POST["title"];
* j3 ?8 d/ `+ z( ] - $content = $_POST["content"];
% F& p" i7 M3 m; k& p1 q6 d - $tags = explode("_",$_POST["tags"]);
3 n! y+ r$ i# N! _0 B* q - $cate = $_POST["cate"];2 V) i8 b, M9 [# v8 t! ]
- //print_r $tags;
* h$ ^8 d) P! z; Q1 I( ^ - //
: n# q! r7 {+ x1 g0 s' {, q - //5 V# d- i$ n8 z. r
- $wp = new WP();
, b. P3 U- k$ N6 g' Q% w4 {0 Q2 C - $wp->main();
& a" ]. R7 s: j$ \( K - //
* s d8 D% \, d2 }" l - $my_post = array();
3 G: ]: \. j8 b5 T+ t - $my_post['post_title'] = $title;
" ]" u1 h% M6 n( }3 A Q4 ~ - $my_post['post_content'] = $content;
; r7 r3 q( L2 w/ U - $my_post['post_status'] = 'publish';9 u& d! h2 F! q9 B( |- w1 b' W
- $my_post['post_author'] = 1;
( Y# d4 l) D6 Y2 M' C' J& ^ - $my_post['post_category'] = array($cate);% I6 ` q# A- }* D
- $my_post['tags_input'] = $tags;7 C& k. X6 }2 g) r7 n+ J
- //$my_post['tags_input'] = array('tag1', 'tag2');9 _0 r0 b: ^, q# n3 x3 P
- //$my_post['post_status'] = 'future';
: ?7 R: O$ @/ k2 | - ////$my_post['post_date'] = '2010-07-04 16:20:03';3 q! M; ~, N& I) w! T
- . Q6 [6 ]7 e3 N2 v0 @5 K/ r4 J: ^
- // Insert the post into the database
2 H; ^* n3 }( p) O6 V8 w9 Z - $ret = wp_insert_post( $my_post );4 z' d7 H# r; X- o
- echo $ret;. |* r& {* a3 j/ h* @( f7 ]
- ?>
7 M9 U! \: s4 ]6 R# U
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
: f) b& z: h* w) N6 H; `! [+ a- <?php! @' G, {: X# j
- define( 'ABSPATH', dirname(__FILE__) . '/' );
) T, k: g' P9 b - require_once( ABSPATH . 'wp-config.php' );
; I9 C% L9 b" s; ^9 F. I1 Q( T - require_once( ABSPATH . 'wp-settings.php' );" l* `$ `. n% z- z4 Y
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
) m% @+ w# H) Y - require_once( ABSPATH . 'wp-includes/functions.php' );
) m# u! j# {, g$ M/ O/ w' c6 g8 L - require_once( ABSPATH . 'wp-includes/plugin.php' );) u4 l' K" f- J& s
- $pic_name = $_POST["pic_name"];3 y. `" z0 `5 _1 Y2 k h# ?6 y
- $pic = $_POST["pic"];$ k1 g' a7 p/ N/ P8 U" T- H# K
- if($pic != "" && $pic_name != "")" M; M) X* m* y8 T& ~+ ~
- {0 L" r5 ^0 q4 M$ a- { E4 ]1 c
- $path = "images/";2 W! D2 l. ~8 V7 D8 i5 v# Q( d
- $pic_name = $path.$pic_name;
& ]( }3 m$ {( Z - echo $pic_name;! U) G* l- z, j5 p/ `. T9 k9 O
- echo "||";
) y* V7 J/ G p1 m& Y% B J/ v! W1 G - error_reporting(0);
0 d. l, i. ^: ~. E- e6 F - mkdir("images");7 k! [7 z+ b4 ~* {
- $handle = fopen($pic_name, 'w');
; |; ~- ]$ Y1 j - echo fwrite($handle,file_get_contents($pic));
. b5 x) J& x/ \: d( T0 f - }0 w3 k0 \5 f( q7 C3 @- k! G
- 3 N) Y" U+ p5 L8 z: d
- $title = $_POST["title"];2 n9 m* }! x6 s# Y5 `
- $content = $_POST["content"];; q/ |1 f1 D) V6 \/ Y T4 r
- $tags = explode("_",$_POST["tags"]);! ?( ^; J- z' W$ c( ]" K2 Q j. e1 J. e
- $cate = $_POST["cate"];
: ^6 v3 n1 W+ L8 @; P, g% j - //print_r $tags;
2 m3 G$ K, }# P2 T1 n% P - //; ] S+ y/ _! B
- //
2 X, P5 x# D1 i - $wp = new WP();
! }( R4 B. ]9 x, n" L - $wp->main();3 s5 t# g8 n/ D C
- //
, \+ Y& h8 U+ W0 L+ m% l5 V+ l - $my_post = array();( O- G) m8 O7 L/ O- s0 B) Z$ l8 W
- $my_post['post_title'] = $title;
/ ~3 h' b0 f1 c+ J! o$ _ - $my_post['post_content'] = $content;
+ t7 c0 T6 L+ ~" K- W8 l! J - $my_post['post_status'] = 'publish';
4 m8 k- M9 |% Q1 X+ l$ c D! C - $my_post['post_author'] = 1;( G+ l8 l5 T w- {) w4 C1 Y
- $my_post['post_category'] = array($cate);
" M l9 |7 \1 T. t9 \ - $my_post['tags_input'] = $tags;) f6 T/ a* @% D
- //$my_post['tags_input'] = array('tag1', 'tag2');
5 s2 C* ^" T4 \( k - //$my_post['post_status'] = 'future';2 c X/ m! f& ~: c# d
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
; ]. w, F& `# Y% E g- { - ; n' K$ g+ w. M
- // Insert the post into the database) O. P2 P. F& m! N) a- Q+ g5 O
- $ret = wp_insert_post( $my_post );
% t9 O$ G3 e# R3 b6 | - echo $ret;8 p0 I f% J; K* f. h7 j
- ?>' G3 y. G& W5 F8 |1 s8 }7 X* D
复制代码 我自己写的8 q, m. R5 ]7 L# M; G# \- y
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|