|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 8 j% F' A# H" v# H% D
$ x" l; r: c/ S/ s; a9 z直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
; o0 x: s8 s& t% R9 g9 S: O+ S
" D" |- ? o+ f; `# ]- N1 N我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
: \" y. u) {* t: T- Z; f2 u9 H& P: Z) e0 {$ V. t9 g
方便实用 简单 何乐而不用呢
- n. V: ]% ?; L- o/ a$ P+ z1 T- <?php
- `, Y D- r" F - & ?' B) D6 c- }1 r" y
- define( 'ABSPATH', dirname(__FILE__) . '/' );
[( ~. S5 b8 h/ g+ P - require_once( ABSPATH . 'wp-config.php' );
4 H% s- O( U7 t( V - require_once( ABSPATH . 'wp-settings.php' );
! R8 s( }+ m3 m d( `6 v - require_once( ABSPATH . 'wp-includes/class-wp.php' ); ?2 z4 F$ I; `6 w' z8 ]
- require_once( ABSPATH . 'wp-includes/functions.php' );* l) t$ Q( |. J/ h
- require_once( ABSPATH . 'wp-includes/plugin.php' );
# @( Z9 `* i* ?$ ~: G; N0 b - $title = $_POST["title"];
* X# D E% X: x6 e7 e/ c - $content = $_POST["content"];4 F0 q7 u" A* r4 o
- $tags = explode("_",$_POST["tags"]);
_6 c) `3 R7 s7 Q - $cate = $_POST["cate"];6 o5 ?& ]2 e% } |
- //print_r $tags;
# \: e$ ?/ t: U `4 g - //+ U2 _# _/ ~* a/ i
- //: q3 @, B4 X8 C. x' a/ m
- $wp = new WP();
: h8 q. ]+ k0 E: r4 Z - $wp->main();
. T! Y1 e' J; Y3 y8 v p) e - //3 Y2 Q; R6 h9 s4 u8 ]! }. V
- $my_post = array();! r0 s/ z( c0 N; V! B% G
- $my_post['post_title'] = $title;) y. V2 A ^8 C. K2 ~
- $my_post['post_content'] = $content;# w& t1 t# {+ K0 Q
- $my_post['post_status'] = 'publish';# C4 B7 e) N8 Y# O2 |' c& w! j; X1 N
- $my_post['post_author'] = 1;! P$ w5 q+ V' Q6 N* `
- $my_post['post_category'] = array($cate);8 V, X9 @ d* g" X$ J6 T7 r2 L
- $my_post['tags_input'] = $tags;
2 L- E' r* Z! N7 c- O - //$my_post['tags_input'] = array('tag1', 'tag2');
( x, N0 r# k. ~ - //$my_post['post_status'] = 'future';
4 v9 g) X! `& _) m8 ~. C - ////$my_post['post_date'] = '2010-07-04 16:20:03';1 j& Y7 I: ~2 W% s2 e' g
) {/ d- | g. d7 f$ a" W ?- // Insert the post into the database
, p" w& p% W1 s. _ - $ret = wp_insert_post( $my_post );
+ P2 P3 ^4 ^! q# s b- f i - echo $ret;5 r9 t- m. Q( N6 V3 B/ c
- ?>
* M3 I3 r# M' c6 s, W* l& H# s
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 8 c1 L, R* y+ C1 x% ^3 h
- <?php
) M* I( [& d3 u3 J6 D: H/ L - define( 'ABSPATH', dirname(__FILE__) . '/' ); G5 [* ?6 `3 Q
- require_once( ABSPATH . 'wp-config.php' );
- P" K6 R& m7 t* N% H - require_once( ABSPATH . 'wp-settings.php' );' \8 B4 h& L0 b: u4 l
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
: U( {/ n6 J! ]: n& Q5 U7 { - require_once( ABSPATH . 'wp-includes/functions.php' );
+ Y' f! E. E# w& M% [ - require_once( ABSPATH . 'wp-includes/plugin.php' );
. g; W9 U9 J0 G% ] - $pic_name = $_POST["pic_name"];9 V4 ]9 J& p; b# E6 i. F
- $pic = $_POST["pic"];
( t0 s2 B) V# N3 [4 c4 y7 U% O - if($pic != "" && $pic_name != "")4 B! t$ a. m5 K7 S1 S v* a
- {
, J) J2 J) W+ i- W - $path = "images/";: }# @( q& P6 i6 H5 G u
- $pic_name = $path.$pic_name;
0 z+ W9 x$ a/ d" S/ b- o! h( X - echo $pic_name;
0 a% f5 Z) w9 s3 Y! U# K. } - echo "||";
* {' `+ J" @, i! n, f, O# q( Q - error_reporting(0);
# e' Y% m. k6 G( h - mkdir("images");
: ~. [8 a. U- e; [2 I3 ?6 ?: t1 P: F - $handle = fopen($pic_name, 'w');$ S& F( `. @6 g3 e/ |0 P. R
- echo fwrite($handle,file_get_contents($pic));
2 h- W# _/ B) R' `# z, w- B/ B - }. q/ t7 {2 \/ S2 T* E' T" {
- : z. T/ \2 |6 \- o ~ }; Z
- $title = $_POST["title"];
k$ @, }8 q& K8 n x" z/ o - $content = $_POST["content"];
+ ^' N$ |$ \8 E { - $tags = explode("_",$_POST["tags"]);
$ p8 k3 l2 B0 G6 }! ^% J - $cate = $_POST["cate"];
- Q% j: e% l# L4 K2 c! L - //print_r $tags;
1 |* _8 e6 H* g* L - //4 _; a! \) C% U3 r
- //
+ B: b2 I8 z p I- S - $wp = new WP();
9 W8 _! w% x2 p! S" q9 N - $wp->main();( v4 b& \4 p2 e$ n, Z
- //
& r' ~/ D; J/ G. K0 K2 s9 i1 F! v - $my_post = array();
& U' O' Z; @" U7 S4 e - $my_post['post_title'] = $title;
$ R' C1 v" R/ [1 e - $my_post['post_content'] = $content;- p y2 \" @6 _+ r( f# s) ^5 ^- ]
- $my_post['post_status'] = 'publish';0 B+ o5 b; n5 F% O6 _: ]9 X
- $my_post['post_author'] = 1;/ S6 h+ u% ~8 q: x
- $my_post['post_category'] = array($cate);
5 h" g. o( G7 a, B9 Y0 u5 d% Y - $my_post['tags_input'] = $tags;
+ x7 i4 `- i# q7 k) U+ d - //$my_post['tags_input'] = array('tag1', 'tag2');2 ~# V. p) Z! q4 F$ T" X* q" h
- //$my_post['post_status'] = 'future';
; [! q9 Y5 C( x - ////$my_post['post_date'] = '2010-07-04 16:20:03';8 O6 d( `6 A- U5 @& ^$ h' M# Z
1 k& p/ P+ O, Y% j, @' a9 _; V- // Insert the post into the database
& w5 S' k8 h; s3 y1 P# v3 P4 I6 x. C - $ret = wp_insert_post( $my_post );
! p: s+ `; H; K- B9 K - echo $ret;
8 B/ ~. E q8 n4 M# |5 [+ O - ?>
, ?) E) G$ C- `2 Z3 `
复制代码 我自己写的
- I# Z2 ]! J8 Y0 J+ L插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|