|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 9 ^, g" R" K. v% x* V: V
8 e D+ y3 P# T' z* Q6 j6 H0 ^
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
4 T2 H. J1 `1 @4 K3 C
' l. s# ^4 e! C4 t% c( i我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了$ D, Y- `1 p" A7 n/ m/ N/ g
( S6 f. m' E, d6 Y
方便实用 简单 何乐而不用呢- 4 N! @' c# {& C! a- ^9 @; ]
- <?php
+ G f9 u9 t* i3 W! A7 z - ! [+ f+ @8 P" y6 ~2 q0 u
- define( 'ABSPATH', dirname(__FILE__) . '/' );
$ z, h; {1 @) V: q6 b: k - require_once( ABSPATH . 'wp-config.php' );+ E. P3 [; e s( W# {* U) ?
- require_once( ABSPATH . 'wp-settings.php' );+ {% `& e& P) U/ x4 d' R
- require_once( ABSPATH . 'wp-includes/class-wp.php' );( r3 z5 y3 v( Z, o
- require_once( ABSPATH . 'wp-includes/functions.php' );$ L4 f9 M- k% Y4 b! p
- require_once( ABSPATH . 'wp-includes/plugin.php' );# V7 f. R( S9 t
- $title = $_POST["title"];, C' J" i' Z/ r0 b: ]; H0 F* o
- $content = $_POST["content"];
( {" u% A4 ~0 e0 `1 ` - $tags = explode("_",$_POST["tags"]);; i$ E- _/ x: |
- $cate = $_POST["cate"];
2 x3 T$ B" v- N! A$ K0 p - //print_r $tags;1 S; V1 ~/ u* ~( Y" {
- //% M) m* B, i _. o7 a j( a1 b
- //
& ?6 K# D7 T$ ]3 o) h6 v - $wp = new WP();
# R; G }( f. A - $wp->main();( J( D1 a) E0 U. J5 y- x/ F0 j
- //7 y7 I9 g1 c! q9 W; B
- $my_post = array();7 h" l9 x+ B) C2 |# d* p. s
- $my_post['post_title'] = $title;
1 p1 U/ m; t* \/ V& R - $my_post['post_content'] = $content;
& p+ ]( J7 d2 d4 P( ~2 g - $my_post['post_status'] = 'publish';) ` |/ q( e& `
- $my_post['post_author'] = 1;
3 S+ Z7 `5 i7 l - $my_post['post_category'] = array($cate);
2 _4 U" E, h) k" \ - $my_post['tags_input'] = $tags;
$ K+ h Z( p' _1 K1 O - //$my_post['tags_input'] = array('tag1', 'tag2');
0 v, q/ e6 j% F2 a - //$my_post['post_status'] = 'future';7 A- @& Q1 `* q, ^0 B- R, e' V
- ////$my_post['post_date'] = '2010-07-04 16:20:03';; R2 J& O% c' ~3 O7 o5 v
- # t, W+ Y3 p( u( d5 C: t& X
- // Insert the post into the database
4 D. }; U# s+ Q; g - $ret = wp_insert_post( $my_post );/ T Q$ N) m$ D' M, X4 W4 d: B+ s' g
- echo $ret;, r v Z3 p' L7 K! }$ q3 z4 P
- ?>
G2 S* A& h! V* }1 c, x
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 7 R# D; c! {8 T) O' l- y* l; f% L
- <?php$ j0 D; W- h" r: ?- Q c/ f
- define( 'ABSPATH', dirname(__FILE__) . '/' );$ F/ A! ~) D- B6 B
- require_once( ABSPATH . 'wp-config.php' );
# a4 O; F/ t% R5 d7 x$ ^& C - require_once( ABSPATH . 'wp-settings.php' );
' ~2 \7 o& ~. j3 ]& U' ]3 I - require_once( ABSPATH . 'wp-includes/class-wp.php' );. W4 h- W0 g1 D
- require_once( ABSPATH . 'wp-includes/functions.php' ); c2 O6 j( R8 K! C0 i( d) s+ @
- require_once( ABSPATH . 'wp-includes/plugin.php' );
" Y' v% [ R" Q: p3 t - $pic_name = $_POST["pic_name"];& K5 C! w: h9 N' ?+ m6 P
- $pic = $_POST["pic"];
1 d B+ i. T% @0 r - if($pic != "" && $pic_name != "")3 m) j. @; ~0 |, j, L
- {1 B* N! V3 i; U: `4 D9 P6 t2 e
- $path = "images/";, q; m! a% m* b" h) c% h; z
- $pic_name = $path.$pic_name;, j2 X$ W8 M: T4 d1 t$ [
- echo $pic_name;4 P, A; E9 F, i0 {8 S/ D2 J/ z
- echo "||";
/ g' C; e% t# N: |) D% ~4 x' x - error_reporting(0);, i9 I; a: }. E/ J9 N. O. X- R
- mkdir("images");* X5 I( I2 `& H' }& O# \+ Z- @5 ^3 G
- $handle = fopen($pic_name, 'w');
3 W$ }, L; m0 v X+ U - echo fwrite($handle,file_get_contents($pic));- ]. Q3 x3 x# f- @7 `
- }$ Q# b# t0 I- U5 N
- : _9 p9 L7 b% ~; Z8 P
- $title = $_POST["title"];9 @, S; _7 H: j& e: d
- $content = $_POST["content"];
% j/ |$ q3 W# m* E# e) n - $tags = explode("_",$_POST["tags"]);) m# \6 Z _8 z' @
- $cate = $_POST["cate"];+ t4 s* v! E6 P) p: }, ]5 e
- //print_r $tags;8 k! T( w8 u X
- //
9 \* Z& y' S1 s' v - //4 a f& H# Z% G. q
- $wp = new WP();# M' n) P: p6 s+ i
- $wp->main();
- {& S! D1 T( c5 P) Q( H; u0 O - //5 ~+ a/ B: ?/ v Q' W s
- $my_post = array();; |- `9 W% J3 _+ [
- $my_post['post_title'] = $title;# p1 }9 K# z3 k
- $my_post['post_content'] = $content;: I `4 k1 u; ~5 B/ y* F
- $my_post['post_status'] = 'publish';
2 ~# @* e. ^ a- d) _ - $my_post['post_author'] = 1;; p% a! W! f C5 g# {- d& I
- $my_post['post_category'] = array($cate);
# L1 {% g8 J5 p) W - $my_post['tags_input'] = $tags;3 w _% M6 g; o6 ]3 F/ {
- //$my_post['tags_input'] = array('tag1', 'tag2');
7 r, V7 J. C0 B0 n! V& G - //$my_post['post_status'] = 'future';) M0 S; C! O8 p
- ////$my_post['post_date'] = '2010-07-04 16:20:03';+ \' R: _( K% E/ Y9 |9 P2 z
3 M+ o% p; t' q- q; R) R# z- // Insert the post into the database
( t7 g: ~- h: z5 `! M/ m - $ret = wp_insert_post( $my_post );5 e+ v8 w1 R8 F: i, {' U: f
- echo $ret;
& g0 K7 ~4 g* y) D - ?>
; M) E$ B/ n+ }& I$ C/ _
复制代码 我自己写的
$ I8 [$ a9 ?5 |4 U) O插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|