|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 2 {* Y. i7 e+ ^& m0 k5 W# E& ?- m( d
4 R E5 {" T4 X( H1 Z0 D! G直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持* d- X \( B8 \8 m3 ?8 G* M
, z2 V! x5 b: |; T0 ^- h我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
0 P2 a$ A2 R, w" R7 u' M* @* r& j6 a. |& Y+ T9 {& u
方便实用 简单 何乐而不用呢
+ s4 h0 n- c* G: _' S$ w9 n8 N- <?php
( U+ o- y$ b; o/ g& [/ n
( a* @* o' |# |$ k) e/ E. n# ]/ P- define( 'ABSPATH', dirname(__FILE__) . '/' );
9 _+ Z W% ~& C) m: Z' ^ - require_once( ABSPATH . 'wp-config.php' );
% F" e6 w! m# p. Z0 y - require_once( ABSPATH . 'wp-settings.php' );
9 ^7 R! a' a$ q8 _; E - require_once( ABSPATH . 'wp-includes/class-wp.php' );
6 k, r* j$ d4 |1 T1 d* Z - require_once( ABSPATH . 'wp-includes/functions.php' );
3 `" ~! b% u7 a - require_once( ABSPATH . 'wp-includes/plugin.php' );
: M3 M/ T+ ]( p5 } - $title = $_POST["title"];1 q$ C0 z! Y* S
- $content = $_POST["content"];: {) i6 \$ v4 k7 r8 g: [/ S( C
- $tags = explode("_",$_POST["tags"]);1 |, Q, V3 X, s8 a0 u0 l
- $cate = $_POST["cate"]; j b& \$ S3 Q6 J+ k# V! k" o+ N
- //print_r $tags;
0 {; q* z5 c) I3 K - //
8 ^5 E; H$ w' `6 r. V - //" P) i. ]# v$ o, m6 l
- $wp = new WP();( x7 B8 i: j) @0 b0 |+ D7 m
- $wp->main();
2 Q# ^" }0 T' v/ H7 @! [/ L - //4 w l3 r/ ^- E T& p* c
- $my_post = array();
7 [$ j& L K6 b - $my_post['post_title'] = $title;
! z \: o4 u1 _8 n* B6 ` - $my_post['post_content'] = $content;
! v4 j9 ]4 g. R! o" P. L8 z - $my_post['post_status'] = 'publish';
7 y2 c, o9 N7 h9 H" T - $my_post['post_author'] = 1;
: X5 H% t. ^% b* T% \) ?$ ^* [ - $my_post['post_category'] = array($cate);
; I. d- S+ u( U* E - $my_post['tags_input'] = $tags;
5 [2 F5 g5 k9 a: b. c - //$my_post['tags_input'] = array('tag1', 'tag2');2 ]0 A" S% H# S8 C- ]% O- G) ^$ @
- //$my_post['post_status'] = 'future';
8 |7 V+ e6 [! B# A) Y/ z& |3 Q - ////$my_post['post_date'] = '2010-07-04 16:20:03';& e$ X. c: q- v, S8 L
- * V. {' H4 J4 b: `, u3 s& E1 F+ N
- // Insert the post into the database
6 {& v' R1 B8 q' R1 d6 X- s - $ret = wp_insert_post( $my_post );$ ^. [" d" a" Y2 I# M0 Y
- echo $ret;! |& o/ u: l+ g5 O6 Y# j! U' H
- ?>1 x. o: M' J1 r
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ( F. Q) B2 e% z! z: Q
- <?php
) U/ A W1 [: m: O - define( 'ABSPATH', dirname(__FILE__) . '/' );
: e6 q, Y7 ?# H8 w - require_once( ABSPATH . 'wp-config.php' );5 ]- r: _# ~( s, o
- require_once( ABSPATH . 'wp-settings.php' );; A3 I1 b1 G- i1 Q
- require_once( ABSPATH . 'wp-includes/class-wp.php' );- X4 l0 X; ]3 T
- require_once( ABSPATH . 'wp-includes/functions.php' );
3 U1 x; h, B: @. g - require_once( ABSPATH . 'wp-includes/plugin.php' );
6 O8 M: z7 h. k' }4 B# p* M - $pic_name = $_POST["pic_name"];
- Q4 ? ~6 o, U* h! m$ ~ - $pic = $_POST["pic"];; _7 u7 G0 i4 v& ?) s3 ~+ J9 g
- if($pic != "" && $pic_name != "")
h4 L2 t* J( i1 V a* c - {, @- K3 W9 J2 U! F7 O
- $path = "images/";& Q. X* B" F& A. ^+ [4 T6 ?
- $pic_name = $path.$pic_name;' Q' }2 J N) L* E7 C9 z9 _3 K
- echo $pic_name;8 R' _1 ]" ~# [3 a
- echo "||";+ [* e/ j: d. P- U0 ?
- error_reporting(0);
1 N; g4 F& {& r1 D - mkdir("images");8 N7 F8 ~* _; s
- $handle = fopen($pic_name, 'w');
1 R& p1 L. m3 G, G8 h( y - echo fwrite($handle,file_get_contents($pic));' q' G- ~8 k' o) g9 q. K; t
- }
0 Q; j9 i O& A1 M- q5 A
2 {( z, @, I- P' Z) X3 f G- $title = $_POST["title"];7 }+ \+ m- P5 W& `
- $content = $_POST["content"];
! k9 K- a6 U" A6 B3 c - $tags = explode("_",$_POST["tags"]);
' U2 H$ D0 |4 s$ i2 L5 ^ - $cate = $_POST["cate"];
& u3 G: }6 [7 o: V* U7 N+ O - //print_r $tags;
: P) B7 L3 h% D3 @# U - //& H& v }3 F' c# Q, i/ ?7 x* v
- //
: V8 x7 W3 ~) y" P) L - $wp = new WP();
0 W3 C" u$ V3 a# r: P - $wp->main();
. m' l8 L' e! Q T' ^ - //# Y1 Z, e5 p0 h( `0 b
- $my_post = array();. i- A/ j% r e
- $my_post['post_title'] = $title;
! a+ d" C) b+ K: G3 p H* a - $my_post['post_content'] = $content;
7 F/ r* b4 { E3 E - $my_post['post_status'] = 'publish';+ u8 I' o5 f% v- C1 E
- $my_post['post_author'] = 1;1 @/ e2 a- k5 B( u
- $my_post['post_category'] = array($cate);$ I2 {4 s; e9 T* R: J& `: h
- $my_post['tags_input'] = $tags;
5 e" T( b8 a! h5 _; Q - //$my_post['tags_input'] = array('tag1', 'tag2');0 y% S' e" e" `% f: Q; v
- //$my_post['post_status'] = 'future';
( e) \5 x: l8 @9 w2 _ - ////$my_post['post_date'] = '2010-07-04 16:20:03';
$ S! A- n+ u" h( f. A4 s
/ X, @1 V% c2 k$ j- // Insert the post into the database' p7 S& [' }" S }- V; M
- $ret = wp_insert_post( $my_post );
9 B8 Q. x3 H+ V+ X- W1 _" P - echo $ret;
* V/ }. ~5 |! K - ?>* y6 M, v% b( p4 I& r
复制代码 我自己写的
- D# ^8 @3 f6 z. F2 c插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|