|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 , y" t# r6 C: f; q
8 ^; n e% F2 A直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持% y. m# z# z# ~ p: K0 N% ]
2 b5 z* [! k& t- M
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
/ q2 E. O/ J7 p* j/ U2 @" @+ d
! ~$ M, o. |: {+ g/ R0 }' K6 c方便实用 简单 何乐而不用呢- ) J- e8 M/ @! b3 ~! q6 `
- <?php6 z3 t" ^; R+ D/ y
- - s/ l$ x$ Z( l. a- W
- define( 'ABSPATH', dirname(__FILE__) . '/' );, W, w) ?+ p4 I# ^
- require_once( ABSPATH . 'wp-config.php' );
! ]+ W/ U. ]- ^" p3 Q V - require_once( ABSPATH . 'wp-settings.php' );" _$ t3 f# O( S4 _( r8 q! \
- require_once( ABSPATH . 'wp-includes/class-wp.php' );: y3 J+ {! q+ y
- require_once( ABSPATH . 'wp-includes/functions.php' );: Y' E! F& B2 F1 N4 \. q% o; V+ {1 `
- require_once( ABSPATH . 'wp-includes/plugin.php' );- g' Q0 H% l! u* O
- $title = $_POST["title"];* k3 Q6 I2 b3 \0 a4 X
- $content = $_POST["content"];0 \+ `7 h- ] Y, s0 i
- $tags = explode("_",$_POST["tags"]);6 ]/ p5 S4 y/ s% F
- $cate = $_POST["cate"]; H' m9 u$ q: W: U0 C
- //print_r $tags;' Q; G; D% g1 }) A4 |6 O1 v9 n
- //$ N. H. k3 l8 s* f, V6 D( r" t
- //
- P! F' n0 ~" F+ ]! {4 T+ f8 d D - $wp = new WP();
4 p0 _; o! l' a9 U- s6 t" x% o3 L9 B - $wp->main();
6 Q, Q/ a& o, K+ y5 o# W: ^ - //% w4 R$ S9 ]) G, l" M8 Z9 P$ O
- $my_post = array();8 L5 m4 t1 P4 H# s
- $my_post['post_title'] = $title;
2 H3 E. b# B h: d9 t u - $my_post['post_content'] = $content;0 |; i9 K3 \2 M% q, [
- $my_post['post_status'] = 'publish';
5 m/ s7 S" v; m/ d j' p O - $my_post['post_author'] = 1;
2 N) j. M" [0 S - $my_post['post_category'] = array($cate);, H/ n8 B" d8 e% u& P ^; ]* b
- $my_post['tags_input'] = $tags;9 o( r$ Q) E: U# ~- ^# I
- //$my_post['tags_input'] = array('tag1', 'tag2');' F4 T$ x1 C9 P2 v/ ?
- //$my_post['post_status'] = 'future'; N1 u' V! ~) |- M9 U, S3 Z
- ////$my_post['post_date'] = '2010-07-04 16:20:03';: q% W, q8 l2 `5 X4 y# z
- J' Q( [# X2 m/ j `6 Z/ }
- // Insert the post into the database
1 v* S8 F% m7 ]4 ]1 T5 { - $ret = wp_insert_post( $my_post ); U% `+ r3 H2 V3 D2 N
- echo $ret;* D( [8 f9 w' ?% V7 a
- ?>) ?! I3 G+ E; K+ g
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ( s3 D8 P2 L+ W9 w
- <?php1 P( {% Z. K8 b: S' ]
- define( 'ABSPATH', dirname(__FILE__) . '/' );3 R% P" T& ]7 i5 I5 d# L% r
- require_once( ABSPATH . 'wp-config.php' );
* w, e) `4 y& X. d3 P1 o9 E$ ~% l - require_once( ABSPATH . 'wp-settings.php' ); f- Z' r1 Q9 B q5 E! K$ e% _! {
- require_once( ABSPATH . 'wp-includes/class-wp.php' );* v# f4 W3 F( w8 U4 H
- require_once( ABSPATH . 'wp-includes/functions.php' );
4 N' S4 u# F% m; a - require_once( ABSPATH . 'wp-includes/plugin.php' );
3 C% \6 U9 }- S) e6 ? - $pic_name = $_POST["pic_name"];9 ~( h: s/ R; H* V6 O- |
- $pic = $_POST["pic"];1 A+ ^( c& ^ }' P8 b( W2 n2 D5 r
- if($pic != "" && $pic_name != "")
" A1 `( n) Y: ^1 Z" v) i! c: B% | - {
. `: ]/ r0 o# X" ~ - $path = "images/";
0 |/ N$ p6 w: ^( W+ y3 @! U8 D" t. W - $pic_name = $path.$pic_name;0 `% ^, l. |; p
- echo $pic_name;0 `/ J" c+ U% ~. H9 t& J4 k& n
- echo "||";
- f: ?6 ?, a( R - error_reporting(0);
, J. Y* K3 h& w4 }1 \; M* E - mkdir("images");
/ {' ~9 Z, M) D- H1 j - $handle = fopen($pic_name, 'w');+ i K6 N m. @4 j
- echo fwrite($handle,file_get_contents($pic));3 h( h+ ?1 V, n0 l1 m' z& b
- }
( [3 e4 N" ^' _* J m8 ]$ p
! A; H1 h; M! m# P6 X0 \) P- v- $title = $_POST["title"];9 m5 c9 I4 W, ~. L0 P& L k
- $content = $_POST["content"];
) m0 a/ J& m( `/ j5 k( b* |+ i5 b - $tags = explode("_",$_POST["tags"]);, g$ ~5 l5 e7 L7 ?7 M, W" S; _' Z
- $cate = $_POST["cate"];
8 h6 `- Q0 i) n( \! ^" | - //print_r $tags;* X. g3 r4 k2 c. c
- //9 ?$ d& n9 T0 D" _
- //
) H6 i5 p" c C( S4 [9 }4 ~ - $wp = new WP();
: u9 o: F/ O* X! ^# r7 n% j2 S - $wp->main();6 K. Z8 L, H6 P: U0 G+ E" a* l
- //0 _8 j3 @2 w* x, ~
- $my_post = array();& R" d7 a4 L" l0 g
- $my_post['post_title'] = $title;( ` @- w" \6 n, ]: @5 q2 @
- $my_post['post_content'] = $content; s# @$ E6 l9 P6 Z2 C, @
- $my_post['post_status'] = 'publish';
2 g* B- ^" T% \ - $my_post['post_author'] = 1;" }, y( R! D6 ^% O0 R" D
- $my_post['post_category'] = array($cate);
" f, ]$ f: \0 g. j% _% R% Y - $my_post['tags_input'] = $tags;; J- h. A6 U1 o! H
- //$my_post['tags_input'] = array('tag1', 'tag2');
0 W3 i$ `+ p9 A# y - //$my_post['post_status'] = 'future';
2 T. Q- _1 A, G - ////$my_post['post_date'] = '2010-07-04 16:20:03';
. S3 T* G( t8 L/ Q - ! h1 Q% @4 J# s& R& x
- // Insert the post into the database J/ e9 W2 F! b8 ?
- $ret = wp_insert_post( $my_post );* l7 H2 p$ B: R3 ~' d2 [$ g# l8 f
- echo $ret;
# N9 S) M' C1 E- a8 f$ v: N - ?>
j' ]$ v, L: K
复制代码 我自己写的
) K0 n$ J" V" Z0 z4 L3 m插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|