|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
3 S7 ^$ p6 C: B! u7 [1 r8 k) n5 Q- q. u
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
. Z, }+ A5 S: \) s) p7 V; R) [% J% @! ]! J9 L7 y) |0 c- ]# Q
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了6 t1 m+ f* `' `* a+ C4 [
" @" o( O& L2 O1 W. \
方便实用 简单 何乐而不用呢- ' j% R, @4 z( L# _- C9 |
- <?php) R# Q' I: a; O; j6 M( `+ _. Y
0 {2 H. j* M8 f! r; \+ c- define( 'ABSPATH', dirname(__FILE__) . '/' );
' u; d# y( n$ r c* b% V - require_once( ABSPATH . 'wp-config.php' );+ @; v( O5 G3 }# Y( s) u
- require_once( ABSPATH . 'wp-settings.php' );
+ z) n4 }: h/ ?/ O& v# P - require_once( ABSPATH . 'wp-includes/class-wp.php' );8 q& z6 g2 E) T) P* ^; q
- require_once( ABSPATH . 'wp-includes/functions.php' );
, Z/ j& T1 [) L: L, k - require_once( ABSPATH . 'wp-includes/plugin.php' );2 i$ G j, }9 y
- $title = $_POST["title"];2 w5 T8 Z* b3 B' o9 X
- $content = $_POST["content"];
1 E1 ^4 g( }7 \7 w& j" S# u7 D - $tags = explode("_",$_POST["tags"]);
R( G8 S' S9 p t: X+ a. K - $cate = $_POST["cate"];
) y' p# [: A+ c6 ]( u - //print_r $tags;
' S$ u# t8 J" e3 F - //7 _$ m9 r6 I+ V2 A! F
- //9 e y( j1 Q# U* [- }& h
- $wp = new WP();
) m8 r9 c" i9 p+ }1 G) {! P( ^8 P - $wp->main();" N6 A1 n. H/ r/ b; j/ [) g
- //8 x' K% y) P! Y5 z/ u
- $my_post = array();( B6 x1 k0 S2 f- |# h& s% B! P% \
- $my_post['post_title'] = $title;
" U5 q" t; h. h - $my_post['post_content'] = $content;. F$ y5 e6 ^/ G+ W9 P! u
- $my_post['post_status'] = 'publish';# u/ U) @6 w+ d. J) S+ I
- $my_post['post_author'] = 1;
/ a! o9 U) _; v# T# C - $my_post['post_category'] = array($cate);
7 ~# s$ k1 G, ^7 w4 | - $my_post['tags_input'] = $tags;& v1 V5 D- I, X2 z
- //$my_post['tags_input'] = array('tag1', 'tag2');+ }" M4 q. S9 p5 i$ I( v
- //$my_post['post_status'] = 'future';
1 B% U e; n% I) @. j - ////$my_post['post_date'] = '2010-07-04 16:20:03';: Z( L8 L1 e, V5 n
- $ d5 G* m" ~9 e) z- [# f
- // Insert the post into the database: m4 P6 y% @% j0 \: M) C* x: q
- $ret = wp_insert_post( $my_post );! p8 w i- f+ i4 j* `* ^
- echo $ret;
o5 ^) p; B+ C4 P; E& W6 v/ ` - ?>
% f! @9 b, D5 A+ g
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 6 r# ?9 `# Q- P. V: S7 M
- <?php
' ^, L% K8 a3 w* w% u- Q - define( 'ABSPATH', dirname(__FILE__) . '/' );2 d k# @1 j9 R" {( E* a
- require_once( ABSPATH . 'wp-config.php' );+ B" p! ]$ g8 r3 _; P
- require_once( ABSPATH . 'wp-settings.php' );
( {8 ]; n/ k. I - require_once( ABSPATH . 'wp-includes/class-wp.php' );
# d' \0 ~5 X+ m3 u. v - require_once( ABSPATH . 'wp-includes/functions.php' );
1 E5 e3 C/ L7 T# ^+ | - require_once( ABSPATH . 'wp-includes/plugin.php' );; a3 E+ `. I- y1 q
- $pic_name = $_POST["pic_name"];( w7 L! q" ?/ D. r' w) T
- $pic = $_POST["pic"];
3 \3 ~: y+ N0 N5 T/ j4 i& y - if($pic != "" && $pic_name != "")6 U) F; `0 C: ]. C: w; \1 y8 _2 r
- {% m, X4 t% E8 s& |5 Z" o- t
- $path = "images/";
, O1 C* ?0 ^+ H - $pic_name = $path.$pic_name;% O/ c, P% `1 \5 X8 A/ V: ]8 s% b3 q
- echo $pic_name;
6 |! S$ a2 N w# X4 R/ m - echo "||";
3 g F# f" t$ x/ e5 `/ Q - error_reporting(0);) F% Z. X; @) p' [6 b
- mkdir("images");
& E. c+ X. z$ g6 A0 u - $handle = fopen($pic_name, 'w');
8 I5 s. w5 |2 M& l) r3 P: B8 k - echo fwrite($handle,file_get_contents($pic));- q" l3 |6 N( z* U N& R9 }/ |
- }. e0 ^6 y7 l0 e, l0 E2 f/ d
7 j+ w4 `* M2 [1 D% `- x9 W9 Q- $title = $_POST["title"];! f) W" W* o' n/ a/ [! D( C
- $content = $_POST["content"]; k- t1 I: `7 Z' L+ h. U
- $tags = explode("_",$_POST["tags"]);0 i- |, T! X' _2 W+ l) W1 t
- $cate = $_POST["cate"];
, G }8 R9 F' I: c" k - //print_r $tags;
0 |0 H% k' R* H. n" } - //
5 t. M! Y+ v3 ?1 J9 t( O9 X - //# }6 I* W$ m* ]3 ~
- $wp = new WP();
" X2 M1 Y5 B. N# ~+ H& H - $wp->main();
0 A1 V" Y$ x ~/ F; p% }# P - //
& ]2 s, g- Q; t2 c# h- c9 x - $my_post = array();
5 x0 |* g/ m5 U" T- s - $my_post['post_title'] = $title;
' S6 j8 [3 n9 p6 s - $my_post['post_content'] = $content;6 _9 o, F" q2 j; T
- $my_post['post_status'] = 'publish';. J4 I- U6 L5 C! Y$ a
- $my_post['post_author'] = 1;
5 y, d$ Y! b+ }1 z! H% j$ \7 x - $my_post['post_category'] = array($cate);
! j$ ]% R. M. | - $my_post['tags_input'] = $tags;$ |2 w! z* B3 P8 x8 e* W5 Q
- //$my_post['tags_input'] = array('tag1', 'tag2');
$ f7 _* y! _! l, ^2 Z - //$my_post['post_status'] = 'future';7 S( M' U/ X6 n6 \# f7 ^
- ////$my_post['post_date'] = '2010-07-04 16:20:03';7 S+ M5 H4 H: n" D+ j$ @2 m7 L
- @! U8 g. d* p7 d' }, q- // Insert the post into the database0 d8 q' m. R- Y2 b6 d7 r. y) o
- $ret = wp_insert_post( $my_post );
0 S* X4 a) |, L. M$ L& r7 N6 B1 ?2 j - echo $ret;- f- H. p0 z# A+ ~& K& k+ P0 u
- ?>
/ X# h' ^( ?# T0 u' A, R$ H. f1 E
复制代码 我自己写的
3 M2 ]6 n' C8 {插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|