|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 & _- l) `8 I' M! s8 Q6 |
8 U7 n, a& x3 [& |直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持* Y1 j6 M: |6 i# p! i8 }# A" ~
[* F/ B$ s S% L2 j
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
9 o) J: Z; T( _6 ^9 ]
1 b' R% v' G! x5 j; v7 f9 A$ J# j7 i9 J方便实用 简单 何乐而不用呢
9 H3 \( q: O; w0 N, m' G2 k- <?php8 s4 @. s {& H" _1 z. j% k
- 5 x5 n, e* `( g0 e2 r4 _
- define( 'ABSPATH', dirname(__FILE__) . '/' );
; I+ v. H6 M' j4 p' ` ], M- E0 U - require_once( ABSPATH . 'wp-config.php' );
7 }! ^: i% A q. b - require_once( ABSPATH . 'wp-settings.php' );
* Y3 @( G- {! W7 Y2 F - require_once( ABSPATH . 'wp-includes/class-wp.php' );
7 E! h0 ]% V: U1 h! m+ _ - require_once( ABSPATH . 'wp-includes/functions.php' );" {$ c# y1 d+ [) z; G' r( X' G
- require_once( ABSPATH . 'wp-includes/plugin.php' );- _" N1 U: [0 R7 ^
- $title = $_POST["title"];
/ ]; l ~# w! ~3 X# O! L - $content = $_POST["content"];
) g. f$ X+ ^- | - $tags = explode("_",$_POST["tags"]);
6 `/ r0 ^; x9 _ - $cate = $_POST["cate"];
6 }# S' R: T: L - //print_r $tags;' X4 B& ?7 X( w9 g. |
- //: _# t6 j+ f' I
- //
/ a; C- n& I/ A+ ~. u. B - $wp = new WP();
- L$ M5 J+ A: r: l) h0 r9 [ - $wp->main();2 W& c( T$ \' u. {8 } f
- //
* m8 f! G/ x7 ~1 o$ |% n/ u - $my_post = array();+ l( l3 r1 p0 L% c1 u1 Z% h1 R
- $my_post['post_title'] = $title;) z# ~+ W3 ?" ~9 E9 h
- $my_post['post_content'] = $content;
; k; q X* q& e% I' Y! o$ a2 S - $my_post['post_status'] = 'publish';
3 W: J4 p, E U* g - $my_post['post_author'] = 1;
5 o3 @: Y$ N5 b/ U2 {, { - $my_post['post_category'] = array($cate);
: M! N, E+ ]) O: [ - $my_post['tags_input'] = $tags;
- X( e4 B5 P! @. E' \+ ` - //$my_post['tags_input'] = array('tag1', 'tag2');: d: T' E. K9 m: c* ^
- //$my_post['post_status'] = 'future';: h& ]4 V$ R+ w! Q4 l. f' E4 O! E
- ////$my_post['post_date'] = '2010-07-04 16:20:03';- o: S1 f/ \- }4 z
! H) Y+ u; q$ j9 H, v, |, n- // Insert the post into the database& g7 v$ V: j8 A5 H+ P" r1 p8 d
- $ret = wp_insert_post( $my_post );
" F' Y( |% ~: M7 f- c - echo $ret;9 h* H* V% V) ~
- ?>
8 ~5 e4 e7 U: \3 w
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
! k4 v! j x5 g3 u7 t# Z6 E3 j, z6 K" r- <?php5 y7 }# W! _; y9 W7 @3 p
- define( 'ABSPATH', dirname(__FILE__) . '/' );. _; p. P7 P& g
- require_once( ABSPATH . 'wp-config.php' );: V u5 J" A2 J3 Q
- require_once( ABSPATH . 'wp-settings.php' );+ d# n* m' e! k7 l, u" W; D: H0 N
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
) D f/ i' J4 x4 ?2 k' c* j - require_once( ABSPATH . 'wp-includes/functions.php' );4 W& J9 Q0 p8 a
- require_once( ABSPATH . 'wp-includes/plugin.php' );+ ` m. A: j _' L. ~) J
- $pic_name = $_POST["pic_name"];
: j: N5 l! ]/ B- { - $pic = $_POST["pic"];3 X/ s6 E3 I, ^) s* ~* Y0 y
- if($pic != "" && $pic_name != "")) m' \* n1 z9 {. j! @
- {0 W+ O: e/ U6 U- G: n- d$ j+ c; \# O7 L
- $path = "images/";
+ I& m! b( p5 o1 s, ` - $pic_name = $path.$pic_name;2 p. [& s# c4 p, \7 K/ ~ X, u$ J5 r
- echo $pic_name;3 t6 Q3 _1 C* ~& n; p& e& @
- echo "||";
% V+ h6 u. a; @; \% F* e2 T - error_reporting(0);/ Y6 A& S: i9 t g. |# q+ l
- mkdir("images");! [/ Q; q# n0 j1 `- F4 v" f
- $handle = fopen($pic_name, 'w');
4 O! X% T- s( y1 l$ R - echo fwrite($handle,file_get_contents($pic));2 Q3 t0 \2 o6 t9 q- B
- }
& j6 ?3 Z4 ]7 x - 5 ~5 m1 o5 H1 d3 \- i: p1 H
- $title = $_POST["title"];- ^7 P J5 b+ K; U2 a
- $content = $_POST["content"];
* b- c7 B$ _7 N9 e5 p - $tags = explode("_",$_POST["tags"]);
3 \0 D0 V! F. l u2 K# [ - $cate = $_POST["cate"]; Q5 Q+ F3 W+ C3 L9 c4 |7 V U
- //print_r $tags;
/ R! q L# X* d3 v% Z3 p5 _ - //# {4 b; |: k3 e5 x
- //! M7 C1 l$ C% h7 G# T( B. R2 W
- $wp = new WP();
$ W7 c6 [" i8 k - $wp->main();# c" t) \4 D: J
- //
* w f' C8 @* g& d# E! o - $my_post = array();- ?; D: o0 l" a: [+ O" _" j; E
- $my_post['post_title'] = $title;' r4 {- S. I! _' A- q7 p O6 N+ g
- $my_post['post_content'] = $content;3 S+ [) _- ^5 X1 [
- $my_post['post_status'] = 'publish';/ q2 b' ?% I3 `: v& c# [
- $my_post['post_author'] = 1;
" H w8 S+ L. J1 m5 g' u - $my_post['post_category'] = array($cate);
Z3 E0 }9 o4 ?" Y( } - $my_post['tags_input'] = $tags;
+ O X- L! Y; q) \' j" A. J' B - //$my_post['tags_input'] = array('tag1', 'tag2');
& S" L7 y! H% f- z - //$my_post['post_status'] = 'future';
, W3 t' V- d8 G, ^) O/ _; G* v - ////$my_post['post_date'] = '2010-07-04 16:20:03';9 V5 T$ ~' f6 t
- % |4 G" V& G. }0 K' u. H
- // Insert the post into the database7 O/ L7 F6 l7 B$ a
- $ret = wp_insert_post( $my_post );
' q8 H6 s5 [ c; `4 B2 A - echo $ret;
. i, M; b: v0 I/ f3 ^) B& B - ?>- e+ S& L6 E5 B
复制代码 我自己写的
" Y! ?, b1 [+ `$ f% J+ x" D插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|