|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
7 ]7 W* M1 Q' Y! w0 H; [
1 q6 K! q3 E2 A直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
* u4 D2 G3 L# K# O; f, v8 m' q7 S- N9 q
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了6 z/ S; U4 Z2 p- e8 o5 L& n3 i
6 _7 y- `1 F& x. E- T方便实用 简单 何乐而不用呢- 7 m" l$ n% ~( a5 f$ {- H& z
- <?php' f/ }, R7 P7 C/ u+ h2 Q4 I
: ?: q" B7 G z6 V. j7 K- define( 'ABSPATH', dirname(__FILE__) . '/' );
7 \# A0 D% z; ^) M( \1 b! k - require_once( ABSPATH . 'wp-config.php' );8 w) I* [' v7 e
- require_once( ABSPATH . 'wp-settings.php' );
+ K( Y* V7 o# y/ e. Q; F0 j0 ? - require_once( ABSPATH . 'wp-includes/class-wp.php' );
/ W- K5 r& h" o - require_once( ABSPATH . 'wp-includes/functions.php' );
# y( s# T! j% o$ t - require_once( ABSPATH . 'wp-includes/plugin.php' );
7 T% n& u6 U u2 F( P3 w - $title = $_POST["title"];
. k/ v: \& m5 m; L1 [ - $content = $_POST["content"];8 e* q5 W2 [' f ^ a2 S& c
- $tags = explode("_",$_POST["tags"]);
d8 h4 k2 [4 R; c% f5 P - $cate = $_POST["cate"];9 ]3 |( ^6 N0 t$ c4 t7 Q2 s1 S8 ?
- //print_r $tags;
& m* p7 K9 b9 B* [) G - //
- C- x# D# M" x' }/ G+ v - //; I; o: H: A) T5 U" P+ ]
- $wp = new WP();
- ]7 c, b* A5 W" K; {* t- H0 [ - $wp->main();
V! ~ @3 j' W: @5 g, j - //1 V0 m$ Z( a6 g
- $my_post = array();3 U/ `/ V# Z8 h+ t& F" X
- $my_post['post_title'] = $title;
( J9 ~& C9 v8 u" i/ p - $my_post['post_content'] = $content;+ G N' j2 p* v- }
- $my_post['post_status'] = 'publish';
- c# V; ^& Q, J! _0 o. u - $my_post['post_author'] = 1;; Z0 E4 m/ j' |7 S2 u. [
- $my_post['post_category'] = array($cate);
( ]9 P% A+ D# q4 j1 A' y0 l - $my_post['tags_input'] = $tags;1 U3 `: ~" z: u6 m3 `: B1 I
- //$my_post['tags_input'] = array('tag1', 'tag2');: g/ l0 Z: {% |5 A8 m" T& y
- //$my_post['post_status'] = 'future';
* ~- G! Z4 l/ H1 d6 A& A$ T - ////$my_post['post_date'] = '2010-07-04 16:20:03';3 |# E- ]) k- G8 g: N+ `
- 2 v& C( v0 p& N3 w; _
- // Insert the post into the database
8 H! V/ {6 G6 } - $ret = wp_insert_post( $my_post );" a, k/ A1 R( d: J& n) }
- echo $ret;; l+ V( I. N/ z4 Z
- ?>
) c! L2 l, e3 w9 w4 G: a' G
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
0 j. O2 B& ~) I# V! H5 o/ |: ^- Z- <?php4 F! k3 X# a' w/ q& F7 ]" p6 P( E
- define( 'ABSPATH', dirname(__FILE__) . '/' );- y; { \& A, I2 k& O
- require_once( ABSPATH . 'wp-config.php' );
1 T, D% }9 q3 n - require_once( ABSPATH . 'wp-settings.php' );
/ K! m' X8 D# F9 Q# \4 U - require_once( ABSPATH . 'wp-includes/class-wp.php' );
* [" Y2 u! P5 k+ k8 w - require_once( ABSPATH . 'wp-includes/functions.php' );
, x M5 }; ]0 W& H8 k; g - require_once( ABSPATH . 'wp-includes/plugin.php' );; X7 x' q' y" n3 \6 I7 B
- $pic_name = $_POST["pic_name"];1 S5 g& S4 f Z; ^" m: g9 e
- $pic = $_POST["pic"];
+ W5 e3 i$ _5 A- X% _ |0 M - if($pic != "" && $pic_name != "")2 U: s) ~% e% Z7 y: W) e5 n, C
- {
, ^& S, N! c( Y7 P0 C - $path = "images/";
* G* I8 o: |' }& E: b7 `6 R - $pic_name = $path.$pic_name; ^6 G; O6 }2 w5 `: M' n
- echo $pic_name;' a0 }$ u( {/ N
- echo "||";
] j+ n$ u9 |# v- g3 c0 R+ E - error_reporting(0);' w2 I: O: O1 u2 y1 J% |
- mkdir("images");
4 q. P a$ b% J! M - $handle = fopen($pic_name, 'w');
& \! i' m9 b4 _& h3 _4 N - echo fwrite($handle,file_get_contents($pic));5 l9 J1 `# m1 q" c% J
- }
& J* G1 R9 k( D5 {- x9 q3 W
+ E& y9 v7 }" }7 c, V5 v3 ^/ f- $title = $_POST["title"];5 r% K- x% H- ]* P5 B2 |
- $content = $_POST["content"];9 v/ v$ k/ T& W6 g% m1 x/ f
- $tags = explode("_",$_POST["tags"]);
( Z) M# G9 Q0 j3 c/ d! _ - $cate = $_POST["cate"];
" D1 o z, |( I# f. a2 a8 | - //print_r $tags;: _ S2 s4 U% ^4 x9 ~* G" y
- //4 d& \% d9 u( H6 d' r
- //
2 p" D- r8 i7 I" I - $wp = new WP();0 L4 t3 J @" H
- $wp->main();6 Z% a; J6 l& e6 w$ v0 Q. S2 K
- //9 M, c h F: @- _) ]
- $my_post = array();
( w1 x8 S, Y+ A5 b q" H - $my_post['post_title'] = $title;
1 E4 r3 c$ ]) \7 V0 ] - $my_post['post_content'] = $content;+ D& j& H# O8 g
- $my_post['post_status'] = 'publish';0 Y) j' c0 z( L8 O7 ?- q! [ u
- $my_post['post_author'] = 1;# Z) `+ z L3 @) J% [4 ~' o
- $my_post['post_category'] = array($cate);' C0 S8 i+ o, b S6 m F3 s
- $my_post['tags_input'] = $tags;' P2 i. ]9 R" s
- //$my_post['tags_input'] = array('tag1', 'tag2');
/ l1 H4 E) s) K - //$my_post['post_status'] = 'future';
: |1 }! R, A3 c0 e3 W, ~ - ////$my_post['post_date'] = '2010-07-04 16:20:03';& _7 l9 ?' x6 a8 G6 D/ b: K
$ u, q; \9 A( V# j* c! j& _- // Insert the post into the database
% D* ~1 M6 U1 n, p+ }, B- Z3 U - $ret = wp_insert_post( $my_post );
* W) d R& m1 `8 N- w - echo $ret;
) g( @. D1 Z, ? - ?>( R' O& V+ n& v
复制代码 我自己写的
, F; z2 m1 _. D1 i; K8 m( W) T插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|