|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 ; K. a" l0 \/ Y$ T- w/ i T
+ e+ @& i3 d' ?7 W
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
1 M- E5 p. m, R0 j% A, u' n( L" }4 q+ [, _( q
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了. T0 J. S: [1 `% l I+ s2 j
v3 [) u% @( B) g, o/ }+ e
方便实用 简单 何乐而不用呢- 6 z6 V* a Q- g# }
- <?php) C7 H* @8 }5 q( ^, r$ U( s
2 E( ]1 p3 g$ V- define( 'ABSPATH', dirname(__FILE__) . '/' );
1 M3 y1 K5 b9 D. [6 r, n - require_once( ABSPATH . 'wp-config.php' );
2 J# ~' l; `4 ?: m3 n2 { - require_once( ABSPATH . 'wp-settings.php' );
& m4 A( a! o& H8 Z5 k - require_once( ABSPATH . 'wp-includes/class-wp.php' );/ r n3 _/ d7 }9 w
- require_once( ABSPATH . 'wp-includes/functions.php' );
- n0 ~9 y1 ?( `. T- } - require_once( ABSPATH . 'wp-includes/plugin.php' );) S& M3 |- P$ @6 u( h
- $title = $_POST["title"];
: U0 y3 B5 P4 O3 z" ^1 p - $content = $_POST["content"];
8 x8 F2 Y+ g- B" l' {3 U - $tags = explode("_",$_POST["tags"]);+ w$ ^$ s* J% z3 ^" M
- $cate = $_POST["cate"];
6 y2 w6 Y' t1 u8 v( R$ R0 \ - //print_r $tags;
4 K ~% @" {" ~6 @ - //; U6 C; |) ^' D+ h
- //
* _ A% I; p1 [/ k6 Z, n3 r - $wp = new WP();
9 R; x1 P' v, X - $wp->main();) B% x- h7 E# e( n) C e, l
- //
4 \% [! B8 e; M: G8 L - $my_post = array();
! L8 t4 t3 u% Q3 [2 `7 H {6 A3 g - $my_post['post_title'] = $title;/ ]8 O6 k. w; r8 h
- $my_post['post_content'] = $content;$ A* c) c+ r1 O8 K
- $my_post['post_status'] = 'publish';
5 g) d1 X6 E$ }! H5 E: k5 t& p# g - $my_post['post_author'] = 1;
+ U4 O2 L5 V& R! i2 D - $my_post['post_category'] = array($cate);
& ^' k, b+ Y# P* ^ | - $my_post['tags_input'] = $tags;. |, [! v8 O4 ~- E1 Q* G% C o
- //$my_post['tags_input'] = array('tag1', 'tag2');
f+ l8 S. Q# l) D6 ^, I1 @ [ - //$my_post['post_status'] = 'future';6 v: t; Z* P, l' K! C
- ////$my_post['post_date'] = '2010-07-04 16:20:03';! Y' ^: M Z1 c+ Z4 W) n
- % J; F0 l2 I( B( q0 f" T
- // Insert the post into the database# o- ?; E3 j1 c6 B7 k1 K/ U
- $ret = wp_insert_post( $my_post );
" Z$ u9 R( ?9 o# S4 b) E0 H - echo $ret;( f G }. s' w: I/ S& l4 O
- ?>: X/ v# B' L6 u6 }6 n* ]
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
" y' a& q7 G: s: B- <?php3 ^6 A Q& Y' h, s8 w
- define( 'ABSPATH', dirname(__FILE__) . '/' );. D# ?# P) s5 t2 ?1 [
- require_once( ABSPATH . 'wp-config.php' );
W) S6 R8 X4 ^% k7 ] - require_once( ABSPATH . 'wp-settings.php' );( ^* K8 U& i9 E4 r5 u
- require_once( ABSPATH . 'wp-includes/class-wp.php' );9 c4 s% h/ K& h- U. b3 L* C3 y1 H6 G
- require_once( ABSPATH . 'wp-includes/functions.php' );' U' l6 r3 M% X* D4 p
- require_once( ABSPATH . 'wp-includes/plugin.php' );9 F3 N6 I, K8 F
- $pic_name = $_POST["pic_name"];+ N v9 y1 ^/ c& F I8 N
- $pic = $_POST["pic"];
- b" X8 X. M- [/ A - if($pic != "" && $pic_name != "")
% v. T- w5 Z1 V) A! y) b4 [ - {
; d1 ?8 Q) G0 v. G/ [* S {' ]8 w$ R - $path = "images/";$ a& O3 F- u/ ^, k, |
- $pic_name = $path.$pic_name;
( |) @- ?3 [" P2 d% b# J4 q - echo $pic_name;
L' K- |8 Y1 M V5 Y - echo "||";1 ? w. C, Y/ ~& n4 E
- error_reporting(0);
% r0 I* d$ D6 w) F. I - mkdir("images");5 H. Q9 \' f y) y( c( ?0 j
- $handle = fopen($pic_name, 'w');
7 i: X3 N* Y8 b4 t5 A! Q/ U - echo fwrite($handle,file_get_contents($pic));4 V9 M g v9 a+ h- k& d
- }
, M t9 @+ A# u6 |0 L2 g
* R6 o: M; x: n) y( ^( S2 G- $title = $_POST["title"];; U! h$ [, A4 `
- $content = $_POST["content"];
- l" p! o/ y9 O1 v, g, v1 D - $tags = explode("_",$_POST["tags"]);
$ |+ H0 M8 c1 q9 a - $cate = $_POST["cate"];# q5 v, x `. w
- //print_r $tags;
1 x6 D; l0 l% ^: @" R, J5 i - //' J! e2 D# N5 |$ _$ E( c
- //* o3 z8 R, D. K0 T& C; R
- $wp = new WP();
- f4 H0 q5 ^8 _& p4 q" \ - $wp->main();
4 J. Q [/ k6 `9 o- ?' q8 a - //( h6 v* o- {3 l+ p M0 M- `
- $my_post = array(); I& @/ n5 b- I! I( c
- $my_post['post_title'] = $title;
/ R/ O4 l( k& K* `; j: v - $my_post['post_content'] = $content;+ [/ _2 ]/ i0 F- ~; b* k
- $my_post['post_status'] = 'publish';
' A+ N, o o6 Q( S - $my_post['post_author'] = 1;
5 ~( u* e3 G* Q! G5 C1 n& K - $my_post['post_category'] = array($cate);5 p" m/ ?: v/ h7 [; v& V
- $my_post['tags_input'] = $tags;
7 c& \+ _- u5 t1 |% o& x8 @( X - //$my_post['tags_input'] = array('tag1', 'tag2');. R3 A3 p/ C1 h+ G2 ^; T1 i) K: T
- //$my_post['post_status'] = 'future';. D4 S- q9 @4 q0 F1 n
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
2 v1 L0 B$ p! L- R. `7 H
3 Z' X% W' {7 B( [9 i- // Insert the post into the database/ r( S1 T) {( M
- $ret = wp_insert_post( $my_post );
) N3 w4 i; d u( g) s+ ? - echo $ret;8 T1 J3 t9 B# r# D0 V: q
- ?>
4 h' ^& R, i. @- p4 M& S8 V
复制代码 我自己写的9 @# e0 ^& q: ]
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|