|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 " I% |4 y! e3 }5 k2 r
+ z& t# X. ~1 [; d
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持 X1 |/ m( I0 {/ C3 ^3 P
6 q- \. f/ _& M& r+ g我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了, n- p0 ]& p% |; @: ^/ m O
" k3 t) ]5 ?; E2 B% H: W" }方便实用 简单 何乐而不用呢
& q' k% A* @8 B7 Y& P# z3 S- <?php6 }; L6 y1 \$ {( l2 I
- 5 M8 [/ N* A* g! V
- define( 'ABSPATH', dirname(__FILE__) . '/' );
0 d K0 V( V( K. W - require_once( ABSPATH . 'wp-config.php' );
% y v/ e { O# s$ { - require_once( ABSPATH . 'wp-settings.php' );3 x& N( a- C% h; @- U( ]$ c
- require_once( ABSPATH . 'wp-includes/class-wp.php' );4 w; r1 A1 I j. u0 s8 `
- require_once( ABSPATH . 'wp-includes/functions.php' );
6 P: r r! x& G% j - require_once( ABSPATH . 'wp-includes/plugin.php' );
" D# j+ w) }3 N/ a3 u# A g - $title = $_POST["title"];
% G+ T1 x0 w0 z8 Q* [. P - $content = $_POST["content"];
8 e& |4 G! j( ^- H- ?# _4 W - $tags = explode("_",$_POST["tags"]);, \8 p, {! g7 ^- u5 I, B6 W" _, N( q
- $cate = $_POST["cate"];
7 O; }' B+ S7 j# X- D/ w) F - //print_r $tags;
% Z* H* n v: {4 U2 W+ ]5 D* T4 K - //* c& R" ~! v; H+ n: Y
- //4 P. t6 Z) a# y! K' ]; D- w9 r$ Y
- $wp = new WP();
: Q. T0 o# C9 {$ ]( |! X/ B - $wp->main();4 p" f; c7 C) M
- //# A! B8 @" t2 l; S6 Y0 n- h
- $my_post = array();+ g t8 N. y1 J5 P# r! _
- $my_post['post_title'] = $title;
( M$ ]; _5 V9 f* ^. i - $my_post['post_content'] = $content;
- V) t- K, `( ?# v - $my_post['post_status'] = 'publish';
: O: F: j1 X- A4 G* K. B - $my_post['post_author'] = 1; e- m) @% |8 w$ d
- $my_post['post_category'] = array($cate);
; n% L! T9 A6 l3 t/ w$ f - $my_post['tags_input'] = $tags;
/ E2 G0 {) Q3 }/ S7 n" G- i9 c - //$my_post['tags_input'] = array('tag1', 'tag2');8 |3 n% z* N( e( P% i! f
- //$my_post['post_status'] = 'future';
7 N: {# m1 L( D! ^3 k' k - ////$my_post['post_date'] = '2010-07-04 16:20:03';8 U* T# ~6 p3 U, o, D S
* A" p7 I& Y; n) P- // Insert the post into the database
2 ~2 M3 i6 L! F4 E, | - $ret = wp_insert_post( $my_post );$ \% Y4 b5 d1 f
- echo $ret;
/ }- { s: t* G& L' x5 z8 U7 R9 b - ?>
/ U' |% g- W( } L0 }
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- & V4 h# I8 c2 h6 o7 l
- <?php
* B7 s3 M. V7 r1 k+ o - define( 'ABSPATH', dirname(__FILE__) . '/' );# y$ g' h; E# z* I$ O! ]
- require_once( ABSPATH . 'wp-config.php' );
/ C9 a4 v+ g- P7 A( y- T4 g - require_once( ABSPATH . 'wp-settings.php' );0 l( W& i8 d }/ Z) [! u
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
( H% P# m0 R( i R; J - require_once( ABSPATH . 'wp-includes/functions.php' );; Z+ t2 K* I* [% j9 O* W
- require_once( ABSPATH . 'wp-includes/plugin.php' );3 E5 y: Q7 \. n3 H, J9 a* z2 r
- $pic_name = $_POST["pic_name"];2 W4 ~( Y% e+ v( M
- $pic = $_POST["pic"];
# k2 r( Z0 b( @3 _5 Y( M0 C - if($pic != "" && $pic_name != "")4 n% G& K9 K. I$ O6 c4 ^* Q
- {
0 j# H- r2 C3 j% `$ t - $path = "images/";
$ o& q( d3 Y- v3 ?7 ? - $pic_name = $path.$pic_name;& ?& b2 ?9 W6 k, a2 V* P* ]
- echo $pic_name;
. o5 p$ w- z7 k6 s/ e( m2 p - echo "||";7 s& j4 i9 q! n0 ~- M+ L* g
- error_reporting(0);: i2 z/ Z& V( Z6 A6 b+ C4 a+ t/ X
- mkdir("images");
0 e+ S8 Q. g( z; x! X, s - $handle = fopen($pic_name, 'w');
. q, U- d) [' J# ]7 `6 E+ j" m3 L - echo fwrite($handle,file_get_contents($pic));) o5 V. h5 _3 b$ f* E- g
- }: U$ O L" v( }0 \' `; D8 D. ]$ P' D
' ]& N' t$ d3 s+ j4 C H. Z* |( ^- $title = $_POST["title"];
* s# w3 }6 D. W4 \. r& h, B - $content = $_POST["content"];
- T- U0 o8 ^4 ]6 v - $tags = explode("_",$_POST["tags"]);' Y/ h- @2 Y0 K) s
- $cate = $_POST["cate"];+ A5 `2 z! V4 w4 I+ M
- //print_r $tags;
% Y$ _! k+ u! h8 n/ w2 I - //. r# u% m7 t9 V% [" S4 f
- //0 v/ B& H8 }: R5 `9 |' u) m6 I2 k/ G
- $wp = new WP();, x) @ P( @# b, H
- $wp->main();
2 J( y# V( E4 ^. v; b7 T0 [1 b - //2 R+ P3 H# b, Z
- $my_post = array();1 {% o; `, A) _' p: D( u
- $my_post['post_title'] = $title;
R* W) V9 O* T6 b V. p - $my_post['post_content'] = $content;9 M; A+ B+ f6 \# z5 S ]1 J2 [2 N
- $my_post['post_status'] = 'publish';
" l' S% ~5 \4 s - $my_post['post_author'] = 1;
2 ~8 r% X* ~! u - $my_post['post_category'] = array($cate);* _/ }3 [: N% b3 d
- $my_post['tags_input'] = $tags;
9 b3 I: u5 `' [ q. G, C( H& ]0 u - //$my_post['tags_input'] = array('tag1', 'tag2');
( ?* p9 `6 S! { - //$my_post['post_status'] = 'future';* }/ z a4 P" g& P" E4 P
- ////$my_post['post_date'] = '2010-07-04 16:20:03'; B- S5 v) Z0 }& d5 D
* A/ X. M) A7 y. @- // Insert the post into the database5 O7 T4 y+ H4 P+ g; K0 N
- $ret = wp_insert_post( $my_post );
" n+ c+ Q8 w7 ^8 E' R5 v7 S0 L, n - echo $ret;( d" e5 C& ~" E, d
- ?>
: b0 V1 I5 I) E
复制代码 我自己写的
0 i+ n% a8 k) S插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|