|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
- i* j4 M' E' ^* f, F# v/ O# w- p8 i# d7 T
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
& H7 J9 T2 l5 X; H. J" Z/ a7 M/ ]( _) K/ d
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
1 r( x5 J9 n, f3 i- ` i ~/ n$ @& K1 }
方便实用 简单 何乐而不用呢
6 ]8 e- b* {' |8 s/ D# ~" v- <?php
# w7 j0 B; S. w% J
+ K% H3 ^' j/ o7 R* a; ?, j- define( 'ABSPATH', dirname(__FILE__) . '/' );" G z+ b) X9 F0 T# Z- c
- require_once( ABSPATH . 'wp-config.php' );
. [; d) ]( N2 m7 E8 ^ - require_once( ABSPATH . 'wp-settings.php' );
) h: c! T8 B, e/ ~) P9 U; v - require_once( ABSPATH . 'wp-includes/class-wp.php' );6 U) g, V2 ^: \
- require_once( ABSPATH . 'wp-includes/functions.php' );) y" S2 l7 {- Y. I* j0 ^2 O
- require_once( ABSPATH . 'wp-includes/plugin.php' );
+ \. E6 O/ J0 J' C - $title = $_POST["title"];& E, s4 m) V7 O3 e0 Q. k9 F
- $content = $_POST["content"];
/ @& H8 e* A4 L+ ~8 H/ b - $tags = explode("_",$_POST["tags"]);
5 J; b" j8 L& r# A; Y( l5 o: j% ] - $cate = $_POST["cate"];1 K/ o, @8 B9 X1 T2 m, \5 r, q) n
- //print_r $tags;$ Z! W% h6 _# T" [$ P
- //
# X( {: e2 k2 L! |- u- s- o- F - //
; ?! I! r. ?) N# b - $wp = new WP();
: _5 ]9 ?6 L/ d1 W0 k/ f - $wp->main();
) s3 L, I8 K+ y) _ - //
) c e8 ?- V4 c1 p0 S, B - $my_post = array();- l1 }: b3 |! J% G
- $my_post['post_title'] = $title;
* [& m% G; d/ @ - $my_post['post_content'] = $content;/ ^. H5 p4 Q! ]4 u) {
- $my_post['post_status'] = 'publish';% @2 Q( v! Z2 z9 h. H6 G; X0 ^
- $my_post['post_author'] = 1;
4 e! t2 P1 {; P | - $my_post['post_category'] = array($cate);
" r+ ~7 O6 g4 c! B - $my_post['tags_input'] = $tags;
! N( c. c/ q; T9 {7 H5 @* ~ - //$my_post['tags_input'] = array('tag1', 'tag2');
/ a/ u% E9 j; m4 r, s - //$my_post['post_status'] = 'future';
% n# z3 F: u8 A$ D. m$ X0 ? - ////$my_post['post_date'] = '2010-07-04 16:20:03';+ Y- f3 I3 ` S7 z
4 o) r! u& _- s; Z$ \) L7 x7 S- // Insert the post into the database- t0 Y2 H+ ?+ H* O7 b" [
- $ret = wp_insert_post( $my_post );' u; f: S/ b. p5 q6 J. e2 p
- echo $ret;
: ^8 H3 x' {/ r+ y) [5 l( G - ?>
U" B" X B+ \5 V3 ~* o
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- + o# _& t9 P' ?3 n- B8 K
- <?php4 B' O! ?2 v. t3 [
- define( 'ABSPATH', dirname(__FILE__) . '/' );
+ _+ Z5 \0 j! _1 b) @5 M( z - require_once( ABSPATH . 'wp-config.php' );
$ Z4 t+ e. K, j1 W" R7 ` - require_once( ABSPATH . 'wp-settings.php' );
* M5 F# ?: k3 I! Y" r0 r, s - require_once( ABSPATH . 'wp-includes/class-wp.php' );
& A* R9 i9 c, B" B8 n, o+ n - require_once( ABSPATH . 'wp-includes/functions.php' );
1 L! ^6 O& P; F: R - require_once( ABSPATH . 'wp-includes/plugin.php' );
x; {7 m: ~1 m. A( c - $pic_name = $_POST["pic_name"];
& e/ S' O+ B2 X) P - $pic = $_POST["pic"];
; F% T S0 X. x. ^ - if($pic != "" && $pic_name != ""), i- p7 X* U4 g
- {$ x& Q5 [6 L! a# }' B) ?( Y4 W
- $path = "images/";# H Z4 U2 t4 J% j
- $pic_name = $path.$pic_name;
. O# ?$ \4 ~2 ?0 ^3 b - echo $pic_name;# L/ t0 N) O: U9 ~3 F. d
- echo "||";4 F, |2 R; \( S$ P% t
- error_reporting(0);. d2 L3 K4 P3 J$ L- e
- mkdir("images");9 n: E& P0 V2 G8 r2 o
- $handle = fopen($pic_name, 'w');6 v! a& a( p# h! P
- echo fwrite($handle,file_get_contents($pic));
* E0 [7 d6 T$ H. L3 }5 N - }
+ e" l2 D# K, `/ I9 c* G - m/ M, n: N5 `+ t# Y# I
- $title = $_POST["title"];
! s* P" d2 p$ e n+ h% Q* c - $content = $_POST["content"];
$ {$ I% L3 `# Y ?$ n4 ^ - $tags = explode("_",$_POST["tags"]);
; {1 [) u% i9 N+ @' ~ - $cate = $_POST["cate"];! a" _" L* I: m9 k" l* u% h0 _
- //print_r $tags;
# h! u5 F( J9 Z4 b& V: e6 C1 s - //; U- X6 f, d+ I6 r- e
- //
- D& R2 A( g/ z% @3 ^. d6 r) x - $wp = new WP();2 I# S/ x( _% I$ ]1 y9 Z2 W; [
- $wp->main();$ f4 K" n. p! J- I0 K4 S. v
- //& O( g0 E3 e) T- X6 w) c
- $my_post = array();
' f9 @1 ~0 Y' u5 u - $my_post['post_title'] = $title;6 E0 P' W E) o V2 j# n; }
- $my_post['post_content'] = $content;5 y! K4 {. T# A. S* I
- $my_post['post_status'] = 'publish';
" }1 o) `1 b+ G2 f - $my_post['post_author'] = 1;8 q4 J4 Q6 N5 N/ F- l$ ?5 @
- $my_post['post_category'] = array($cate);( A8 s7 n3 Y3 p
- $my_post['tags_input'] = $tags; K6 m. }1 o3 O% t8 X
- //$my_post['tags_input'] = array('tag1', 'tag2');
+ a) S$ _ L" p" W' C( O: C; y - //$my_post['post_status'] = 'future';
! f! _8 U* m# C/ a: y - ////$my_post['post_date'] = '2010-07-04 16:20:03';. e1 U' u; X+ L- y; u
- $ G/ C- r) j+ I0 T
- // Insert the post into the database
6 `& Q9 b8 ^) H0 }8 P - $ret = wp_insert_post( $my_post );( h8 r; H5 W4 K! ?+ r
- echo $ret;! C$ Y$ D/ Z* f2 I
- ?> Q3 c; {# F* d4 F- d; G
复制代码 我自己写的) D- @/ |8 @) m( @1 c
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|