|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
6 B4 M( W `% {3 r) p! ^! i g3 i5 Q
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持; r, Q0 ]0 Z+ t3 v3 O. |
, d* h) i H7 ]7 f2 w我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了; N. u' E4 i* P
/ o+ E/ S" s. S0 P1 g6 J; L
方便实用 简单 何乐而不用呢
- ^) k6 I$ N, ~5 h- <?php$ ?3 d! g3 ^2 \) |8 X& V
t; m( E, i( N6 H- define( 'ABSPATH', dirname(__FILE__) . '/' );
9 f' L; J( J0 [; e8 M: n) B - require_once( ABSPATH . 'wp-config.php' );* [. _+ D9 w- {* C- z
- require_once( ABSPATH . 'wp-settings.php' );4 ]" j: b! q, j8 \) D
- require_once( ABSPATH . 'wp-includes/class-wp.php' );% X( T* G7 P: T8 l D0 I1 @. C; a5 d5 g
- require_once( ABSPATH . 'wp-includes/functions.php' );. T1 N- a4 A2 b9 e3 T& Z3 k
- require_once( ABSPATH . 'wp-includes/plugin.php' );
% ]! [9 C; u! F/ e/ T. o5 N( _ - $title = $_POST["title"];
3 f2 c1 f& y y5 Q7 O/ t6 }, X - $content = $_POST["content"];) A! {# } j# u" L; I" t" g9 }; @- t7 r" M
- $tags = explode("_",$_POST["tags"]);
) x# P2 S2 K1 H: t/ ^8 ~$ i - $cate = $_POST["cate"];6 ^; _3 R& h# w$ ]) ]
- //print_r $tags;
8 A# ]' N2 E# f. J - //! a3 E* E) d- E v' k0 v4 E$ l
- //
4 S8 D: Q5 c7 h; u# i) q) K& I" B, O - $wp = new WP();
* `1 Z* I" t; X - $wp->main();" b5 T& q- Z3 ^, Q) j$ p4 r1 g
- //
7 \& ^# y/ Y$ k" k. T9 `7 G6 O - $my_post = array();3 M: a3 _6 N7 g, b2 Y
- $my_post['post_title'] = $title;- b s. l' d% q0 y( Q6 j
- $my_post['post_content'] = $content;
- e, m! l) q1 ]3 V - $my_post['post_status'] = 'publish';
# c; M/ L+ p5 n- Q+ f - $my_post['post_author'] = 1;. }" z7 ^3 O8 t6 b3 W' X
- $my_post['post_category'] = array($cate);' \9 U7 @; ]2 p" r
- $my_post['tags_input'] = $tags;, X: x- _- q- \* u
- //$my_post['tags_input'] = array('tag1', 'tag2');+ y, L X: X2 I- [" k4 d
- //$my_post['post_status'] = 'future';
2 b! k$ [! ~3 {+ Y$ ~1 H3 H E, j - ////$my_post['post_date'] = '2010-07-04 16:20:03';
: {8 M" m! r% a; M/ ^" z) ?& u
7 @ T7 ^7 c8 H, } P( Y5 Q- // Insert the post into the database
8 L3 C5 H" h+ ]" G$ a# `2 R - $ret = wp_insert_post( $my_post );) C/ K7 r o# `
- echo $ret;
/ E* a/ B. [; F6 i% c. s - ?>
- R: I2 D4 C- r4 {8 a7 u1 ^6 g
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 5 L. x/ D1 l1 ^4 {, m E
- <?php: j2 r; Q/ I; @1 U& U
- define( 'ABSPATH', dirname(__FILE__) . '/' );
5 D- S% Z4 X/ M( n& z - require_once( ABSPATH . 'wp-config.php' );
3 d& J5 d( }( p4 a4 T- A3 _ - require_once( ABSPATH . 'wp-settings.php' );
" W7 n2 p2 c/ T. W, ?* a' `7 U f - require_once( ABSPATH . 'wp-includes/class-wp.php' );
' J: y* u( b. I! U! n - require_once( ABSPATH . 'wp-includes/functions.php' );
& e. W6 y8 c% l - require_once( ABSPATH . 'wp-includes/plugin.php' );% `! G: `$ Q# e$ b, W) |7 f
- $pic_name = $_POST["pic_name"];
! `9 y( i6 s# g' W( N5 s - $pic = $_POST["pic"];6 ?0 ~' V, \1 }$ `* P
- if($pic != "" && $pic_name != "")1 _. m) m. A0 F/ D) n0 H
- {
' r; d' t. ?+ E* m - $path = "images/";# `8 F7 P, T" C' B) K/ ?
- $pic_name = $path.$pic_name;0 s# P; n8 c9 K
- echo $pic_name;
! {4 R% u# K; A8 R - echo "||";
' a! b! G( s! {$ l. b& q; S - error_reporting(0);1 h+ @+ _! t: v( i' @9 |) w L
- mkdir("images");
1 Q q& s4 P- u* S - $handle = fopen($pic_name, 'w');
: a* z- ?5 f% E5 x) y& Y - echo fwrite($handle,file_get_contents($pic));- q; ]* y" }: v2 I" ?" w
- }
; l; C; K( U! d8 ]# } - 1 l3 X! h7 H6 @- a
- $title = $_POST["title"];9 s( M# p- s) h. N$ N4 x( B9 ?1 q
- $content = $_POST["content"];8 @1 E5 b* V4 h) u8 x+ P
- $tags = explode("_",$_POST["tags"]);& [/ U- E$ t- Z' K }: S6 V
- $cate = $_POST["cate"];
! I8 Z$ S7 r5 d! R$ V% U, Z - //print_r $tags;3 ~! n$ \ U$ ]# R
- // ^9 Y7 s! ]0 }* Q2 T4 r
- //! v- p: H1 @! h( B, U+ X; `+ ~0 Q
- $wp = new WP();
2 x. K9 o/ q- M& K: n3 _, t - $wp->main();
/ _1 F/ r2 o6 u' j/ F - //5 O% H! c# T- r4 ]
- $my_post = array();
: q8 e: U( b1 k% l4 F& v - $my_post['post_title'] = $title;
4 ]& u3 z) C0 W7 a - $my_post['post_content'] = $content; n6 g: E' A( m
- $my_post['post_status'] = 'publish';
5 Y8 u8 q" |, [ - $my_post['post_author'] = 1;5 K+ X! q8 {: r1 y- }: a4 v. `9 [& y
- $my_post['post_category'] = array($cate); O2 u5 f1 p1 q& q8 g: F v
- $my_post['tags_input'] = $tags;( l9 }0 ^- N$ ^* d1 E2 w
- //$my_post['tags_input'] = array('tag1', 'tag2');3 S6 t, S7 B; n
- //$my_post['post_status'] = 'future';
/ z# L, j, N6 A; Z' I5 r+ o$ V - ////$my_post['post_date'] = '2010-07-04 16:20:03';
( c9 y4 s. \; g# ^% q& ]4 |& e: B
, i" h4 b8 [( U# H- // Insert the post into the database
7 S2 d4 @- V" L3 o8 e, ^) { - $ret = wp_insert_post( $my_post );: |, P( H" @; t/ m8 ?* W
- echo $ret;
/ z" f$ X$ K8 F4 ` - ?>/ x* g% |; T: _ I# ]3 \, g
复制代码 我自己写的% P0 z Y" I7 Q- ^4 c$ P
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|