|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
# `* \' D% z% ]: j1 h4 ~) M( Q+ R& f( Z
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持# L8 {+ l0 }" N3 U' L3 x
' S, b4 A7 J3 ~* Y9 S K我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了1 F/ q1 _- H+ T) u% z2 N
- o% Q; M& U+ t/ a3 }( Y# y% q# F
方便实用 简单 何乐而不用呢- 3 l8 K/ m# ?& C
- <?php4 u- B; g: Z2 E' p4 b5 H) d
- ) z Z, B5 f7 P' ?
- define( 'ABSPATH', dirname(__FILE__) . '/' );
8 a% S& L n7 T9 [- b) P8 h- E - require_once( ABSPATH . 'wp-config.php' );
# l* r# ?4 q1 }; }# p* f - require_once( ABSPATH . 'wp-settings.php' );
+ ^! w8 D3 l; ?8 g - require_once( ABSPATH . 'wp-includes/class-wp.php' );0 M/ w$ [7 I& N$ h& @% Y3 w
- require_once( ABSPATH . 'wp-includes/functions.php' );) }; ]6 H% H0 c
- require_once( ABSPATH . 'wp-includes/plugin.php' );' ]9 L: N/ t' m+ o& n
- $title = $_POST["title"];; J) f7 T1 P2 W5 C" r! s0 G L
- $content = $_POST["content"];
5 ?" J, `* w: n) o( e: l - $tags = explode("_",$_POST["tags"]);1 U/ P- q- o o0 b% w1 l. g
- $cate = $_POST["cate"];
5 x+ L; t0 w2 P - //print_r $tags;; O& p) d# F$ Z/ B
- //
4 N$ z( `" F2 W# V% d - // g* Q* i4 H }7 H/ ] j, f
- $wp = new WP();
2 {9 Y/ d7 }' h; h) ~' e) n. {% T - $wp->main();* x0 a% C0 Q& |- P( g" S
- //
( G4 {' j+ \( i% L( w7 M - $my_post = array();
# @2 r/ ]; K' i8 i" n c0 @2 F - $my_post['post_title'] = $title;
' D) p/ O: `# l - $my_post['post_content'] = $content;; H' w3 K& F) F8 d4 \: M B# `
- $my_post['post_status'] = 'publish';2 |, O7 p v X* u$ k: \( G0 N N
- $my_post['post_author'] = 1;
~* ?0 w3 D+ a n - $my_post['post_category'] = array($cate);; i+ f: h2 {: i2 X
- $my_post['tags_input'] = $tags;$ D* V3 {$ V" g8 M' p; _ ]
- //$my_post['tags_input'] = array('tag1', 'tag2');3 H! v! j7 H3 D: a9 M
- //$my_post['post_status'] = 'future';& R# G& h$ e' z% v' ? r n
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
9 x! _: H+ E5 S1 b8 F, X+ ~" Q
: b9 U# j1 A* Y/ {. ~7 u% U- // Insert the post into the database
6 p& n$ @! U9 t' j - $ret = wp_insert_post( $my_post );1 {4 T& L. ]# J0 R# H0 ^: W; N
- echo $ret;: Z" A5 U/ C; B$ q9 s
- ?>/ k' p, {& j" i$ h8 F) K
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
k) y' ]+ C" _" \" \2 z. ~, h- <?php w8 F' R# e5 N1 H+ Y" j
- define( 'ABSPATH', dirname(__FILE__) . '/' );: }4 n W6 w2 ~/ ^* c' A
- require_once( ABSPATH . 'wp-config.php' );
/ b9 d) y) I+ l$ l1 J/ h0 z3 ~, w - require_once( ABSPATH . 'wp-settings.php' );
3 y/ e3 z4 N/ Q* ^# t+ a$ x/ i& c - require_once( ABSPATH . 'wp-includes/class-wp.php' );& D9 m$ j s0 l B* X. D4 [* C
- require_once( ABSPATH . 'wp-includes/functions.php' );
2 S+ W7 V" `0 C' W5 ^+ G/ [' k5 y) s - require_once( ABSPATH . 'wp-includes/plugin.php' );+ a- y- z$ q V- k |* X
- $pic_name = $_POST["pic_name"];
5 r4 i0 A, J) a) s$ H - $pic = $_POST["pic"];
7 }9 g. z0 O$ l+ g5 o' S# b - if($pic != "" && $pic_name != "")
( V9 C& Q H9 r, t/ d& b - {
, }( l+ P( Q+ F( Q( u - $path = "images/";
& n; z( S0 \. `7 e) w8 q - $pic_name = $path.$pic_name;
; S: P& k, W9 p5 y - echo $pic_name;
6 s# m" X! ~9 c1 I0 { J. B2 @ - echo "||";
8 s" g: h! P/ r - error_reporting(0);# Y- ?$ i, `8 }* z8 M! L
- mkdir("images");( ~& S1 ^" U; K2 K3 ~8 j
- $handle = fopen($pic_name, 'w');
4 ?7 c6 q3 `: r) T8 w - echo fwrite($handle,file_get_contents($pic));7 Q/ A1 r' m$ f$ l
- }
. F, c5 |" S+ _, @+ t7 d9 {8 ?8 M
5 R- M- Y, F' f2 S8 O4 ]- $title = $_POST["title"];6 ]- ?( \6 t1 I0 f5 y) E; |4 f
- $content = $_POST["content"];
2 b1 H2 n* _, W: G8 P2 Q( [ - $tags = explode("_",$_POST["tags"]);
; O2 v, B3 D; D' Z+ m6 V3 I& [ - $cate = $_POST["cate"]; f9 B) c, X7 Y' l& L
- //print_r $tags;
& s7 c7 _, S/ ]) r+ u. \ - //! D7 p f0 B8 ~6 Q2 t; ?+ w% p) U
- //% z: k+ U( M- C0 j7 W
- $wp = new WP();0 [. Z' A Y4 p- C
- $wp->main();
2 H2 s8 k: `6 o) c, g6 s# ? - // l+ U- h3 Z: k r) Y6 Q
- $my_post = array();
0 g2 k |* |& [ - $my_post['post_title'] = $title;8 o# ?& T3 ]1 }8 k7 Z- k
- $my_post['post_content'] = $content;
1 K- t# }6 q9 J! Q - $my_post['post_status'] = 'publish';
& x2 |6 P( x8 I3 T8 o, ` - $my_post['post_author'] = 1;
2 a" ?( B& J$ i3 b+ c/ h r - $my_post['post_category'] = array($cate);
- V4 H7 I. n- z; B - $my_post['tags_input'] = $tags;; }) ]0 p' i5 t( p
- //$my_post['tags_input'] = array('tag1', 'tag2');
7 M+ |) m& C9 {5 M$ R6 V1 q' Q+ ^, J - //$my_post['post_status'] = 'future';
) l. A& N F0 V4 ?4 v5 s# |- O3 x; n% G - ////$my_post['post_date'] = '2010-07-04 16:20:03';
3 C' \- [* w3 x7 ?0 e X
- v& s; q: `+ H% S- // Insert the post into the database
3 g. M; Z' R) n- j/ l" g6 @ - $ret = wp_insert_post( $my_post ); a+ | h& \" t- p8 g
- echo $ret;! ^- Z" O3 [" i! O$ b
- ?>
$ j% W3 B% ~5 Z z
复制代码 我自己写的/ s* ~# v/ ^7 |9 O t. f3 p; A
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|