|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 1 P" n& |/ w% P$ s0 t$ ]3 F
% a' t# c: K5 t5 U
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持& B2 ?; }! K# U3 o) ]* m* v
/ i3 {/ b& [- c3 {我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
+ C F# E6 U& k7 c; t5 |0 C+ Q( z0 c0 |/ ?/ A+ k
方便实用 简单 何乐而不用呢- 1 {! V, k* b* \1 a6 G% }% S
- <?php5 R; h. f) r# C5 A& f0 r
# }* t8 w5 {& [! m6 s- define( 'ABSPATH', dirname(__FILE__) . '/' );
* _% u# z( [$ q, e1 C - require_once( ABSPATH . 'wp-config.php' );
: o. S Z. e9 j2 M M( V- Y - require_once( ABSPATH . 'wp-settings.php' ); P* J& y) J9 K* _
- require_once( ABSPATH . 'wp-includes/class-wp.php' );: t: e) k8 e6 u
- require_once( ABSPATH . 'wp-includes/functions.php' );
2 R. _+ h& @0 F2 ~' O - require_once( ABSPATH . 'wp-includes/plugin.php' );
7 {5 v8 V/ Q. o1 `4 C - $title = $_POST["title"];# E3 ~9 C' t3 }5 y. D
- $content = $_POST["content"];
) n' C9 E6 E- G, K) b3 R% u# }1 I6 R - $tags = explode("_",$_POST["tags"]);, B m1 i z; v- y& \+ }
- $cate = $_POST["cate"];
9 ]7 ?( d2 @4 E - //print_r $tags;
+ o }, d5 ?* O! U( H - //. ^# S5 \( E+ z4 J, b: X
- //
) H' Q, p5 \7 D+ f0 q: G! l - $wp = new WP();
8 {! Q& m0 h" d# d - $wp->main();
5 q7 q7 ^; O7 E, u% | q# q% b" j3 O' J - //8 z& X% n6 | L( q
- $my_post = array();
. v. r3 o6 W( {& t. c* d - $my_post['post_title'] = $title;$ g& S+ i& U" p: g) y8 d
- $my_post['post_content'] = $content;
* p; V9 ]3 ?6 n - $my_post['post_status'] = 'publish';
! C$ g9 v, z5 F5 B. B5 \6 i - $my_post['post_author'] = 1;
( J7 m6 ^4 d7 y O, p - $my_post['post_category'] = array($cate);
- ?& ?- C7 A& R9 n) P8 @ - $my_post['tags_input'] = $tags;4 U+ U5 z1 Z: f2 {3 R/ s" |
- //$my_post['tags_input'] = array('tag1', 'tag2');
0 _8 E1 I2 P, _; s, K4 S0 U# p$ P - //$my_post['post_status'] = 'future';2 y% v [8 ?1 [+ ~3 x
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
& Z2 n+ c% p _8 @2 O1 u/ D0 C8 A - 8 w7 c, V( D" s7 b. f! [
- // Insert the post into the database
5 d' D! r2 |8 |5 h - $ret = wp_insert_post( $my_post );
6 T4 X* s9 }5 W5 h v - echo $ret;
$ J" p% m' U1 `& l9 ?, |1 T( A# t( ] - ?>/ [. [( J- p8 K, O; {2 c3 }( @; S
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- * M, z* C( F- Q0 Z6 U7 s2 z0 s
- <?php$ y9 b. N6 R5 i. k& S" S
- define( 'ABSPATH', dirname(__FILE__) . '/' );' |" N8 V( F ~
- require_once( ABSPATH . 'wp-config.php' );* F8 F# ~. [/ t4 J1 i8 l
- require_once( ABSPATH . 'wp-settings.php' );! ]5 B: g( p- Y2 V$ Z9 Y
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
9 m( I# s3 @8 B$ ^3 u+ r9 [$ T - require_once( ABSPATH . 'wp-includes/functions.php' );
# `" R+ d1 }" M6 ^& @ - require_once( ABSPATH . 'wp-includes/plugin.php' );4 C& t- F# o7 K* ?9 K
- $pic_name = $_POST["pic_name"];0 N, ^4 x$ E9 ?
- $pic = $_POST["pic"];4 T" j* y* {# B+ s( I0 u1 }
- if($pic != "" && $pic_name != "")
* z- N. c: W8 v0 c( |8 D9 l - {
_ g) H; H! p) f+ d. I - $path = "images/";8 j, c: {9 T" Q9 Y2 b A
- $pic_name = $path.$pic_name;" k2 n' H" F& J3 a( e8 B$ [. i
- echo $pic_name; l; g; o+ H p4 s; `6 E1 \& Y8 q
- echo "||";7 l/ b3 i v5 B, ?. I
- error_reporting(0);
! Y/ F% |( E! B w7 u! g5 C$ _ - mkdir("images");
5 N9 `2 y1 z: P/ W( S - $handle = fopen($pic_name, 'w');7 X5 _6 G8 E- P" n$ m9 ~8 b+ R4 }
- echo fwrite($handle,file_get_contents($pic));
$ }, U- y- b* {0 R; O5 y - }: o5 \! R, q* }/ j( ]( B7 i' k
! ~, C2 H. m- N0 r3 u- $title = $_POST["title"];: [& x1 }2 @, \( j+ }
- $content = $_POST["content"];
1 ?9 _' {$ a7 w- A' P0 z# H8 g* O' l - $tags = explode("_",$_POST["tags"]);; K% v" g' A7 d# z6 T3 D. S
- $cate = $_POST["cate"];% ?- F. n2 j6 q4 x+ ~' r l
- //print_r $tags;4 g8 b$ z0 m- k$ b! t% [$ L2 f# F
- //
' u8 }0 Q# S) k2 X7 Q - //
+ n. B% t1 s% a% T; _ - $wp = new WP();8 j* C8 m/ R3 m& @1 o
- $wp->main();: @ K( W |: {: B' p9 j7 [
- //6 d+ @+ L8 y/ @. O; P
- $my_post = array();+ l0 L& `/ N/ d @3 ]& P5 b7 k
- $my_post['post_title'] = $title;/ c. \) f. F W
- $my_post['post_content'] = $content;5 h: h8 w% {' N* i
- $my_post['post_status'] = 'publish';
3 c) O% k- G) E; t; E - $my_post['post_author'] = 1;
* w; j- s+ H& M! {5 z F* i3 b - $my_post['post_category'] = array($cate);
$ L& W4 N$ }9 n! x0 z8 V - $my_post['tags_input'] = $tags;+ V9 I. \3 `$ v$ [
- //$my_post['tags_input'] = array('tag1', 'tag2');
- ?' J* v% v* d, ^9 B$ n! T - //$my_post['post_status'] = 'future';: h' H9 @5 a" H, c' Q+ W* K
- ////$my_post['post_date'] = '2010-07-04 16:20:03';! \) J# c5 t7 } f
- ' d2 [4 R1 _; f2 j8 k3 t
- // Insert the post into the database
7 ?& ?$ C1 j6 R8 ]3 L - $ret = wp_insert_post( $my_post );* l0 w6 ?9 k3 h% v- v+ S
- echo $ret; S1 R0 V% B, y- V C9 V
- ?>5 i$ z6 j* H V4 H. F6 W
复制代码 我自己写的$ B$ q* o8 F( T- i; ?
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|