|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 4 s! m% e: ]- ]" }8 [9 w
* H2 i; M* F; n1 c+ i# {
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
8 q0 U0 W5 d, d. I7 Y& I1 ?+ `3 F) q
$ ]- j! m2 t2 ], o, X3 y我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
+ t% Y. |0 s4 @4 [. ~4 p1 X
9 u( D9 q9 N- V, d/ K" M: M/ [ a方便实用 简单 何乐而不用呢
) |& Y9 |) ^# ~7 [- <?php
1 ~6 |1 g3 `" Z6 J7 Z5 l9 w - 4 f- ~" V; |( |3 v! f2 I) r8 |) |
- define( 'ABSPATH', dirname(__FILE__) . '/' );
' k2 i$ M0 x9 Q* d - require_once( ABSPATH . 'wp-config.php' );
2 w+ d( F9 E, y - require_once( ABSPATH . 'wp-settings.php' );$ Y* ^( i% j. z* N( z
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
" g$ a S0 l* L* a. b3 o - require_once( ABSPATH . 'wp-includes/functions.php' );
6 F) O, e3 [$ @( {/ R& Z - require_once( ABSPATH . 'wp-includes/plugin.php' );5 ?* K# m _- Z; p7 {1 a) p
- $title = $_POST["title"];
, F' l! y6 l) { v - $content = $_POST["content"];$ s0 ?$ ~$ k3 i
- $tags = explode("_",$_POST["tags"]);
, O- A0 U' l" r - $cate = $_POST["cate"];0 F+ V8 i/ I2 q" W! }: i' T
- //print_r $tags;
2 O) _5 @* {9 S* D - //
9 i6 W" g( J+ \/ o9 V) l) i# V - //, d/ ?. J/ p4 b' s. H& K/ @
- $wp = new WP();& G9 V* Y5 G2 H% B; I
- $wp->main();1 k9 O/ c! c2 [
- //
/ R! B$ A9 Z3 e+ \- h* X - $my_post = array();9 c$ c: O+ @1 i: }2 q% r
- $my_post['post_title'] = $title;
) c* M. z; \6 U* g* _ - $my_post['post_content'] = $content;' d( S2 k* R- Z3 h' c6 {
- $my_post['post_status'] = 'publish';
2 h5 \$ \. ]* ?" [# k2 _$ O+ P - $my_post['post_author'] = 1;" T: G v9 u6 p! l. L
- $my_post['post_category'] = array($cate);
: z2 Y8 ^, ]; J3 M& b- L8 P - $my_post['tags_input'] = $tags;$ J' p7 ]: z# [8 y( d* n7 x
- //$my_post['tags_input'] = array('tag1', 'tag2');# m6 j! a) p6 g+ O+ q* g
- //$my_post['post_status'] = 'future';7 w/ m# K5 I+ k$ o" }* b; a
- ////$my_post['post_date'] = '2010-07-04 16:20:03';- ?, O9 P4 @# `$ s1 q b h+ T. v6 }0 ]
& W4 E1 l1 Z6 d% R v# J, f- // Insert the post into the database2 S/ A6 f. \9 U& A K: V
- $ret = wp_insert_post( $my_post );
* A: ?7 V6 ~2 c$ u - echo $ret;+ C ~7 w( z1 p: `: {! L
- ?>
5 T, X; h/ v; c6 j8 l; j
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- : ^* {2 a8 L1 r8 L% F9 e
- <?php6 \2 A7 I3 x% @* k! F1 Q2 ?0 K
- define( 'ABSPATH', dirname(__FILE__) . '/' );0 [; P2 G8 _# Z
- require_once( ABSPATH . 'wp-config.php' );
* c5 B9 M9 A8 \. |4 P4 W1 ] - require_once( ABSPATH . 'wp-settings.php' );
1 V) B3 p3 R7 \ W0 J - require_once( ABSPATH . 'wp-includes/class-wp.php' );
1 J2 y; z" k1 c( t0 N. P) x; _ - require_once( ABSPATH . 'wp-includes/functions.php' );
3 M! E/ u, J. F% m9 ] - require_once( ABSPATH . 'wp-includes/plugin.php' );1 q3 B/ q3 t2 V% I" ^2 c5 Z5 N
- $pic_name = $_POST["pic_name"];
0 W! |9 ~6 M8 M$ U: D - $pic = $_POST["pic"];; T* B- q4 Y# v$ T0 K
- if($pic != "" && $pic_name != "")' ]" ^) P( d9 N' P# q# P, x0 `
- {/ ?! A0 c! I$ [! a* p _& i G
- $path = "images/";
) @" n( a P1 G9 a$ l - $pic_name = $path.$pic_name;
8 B9 U8 b! [, P3 b2 k8 r - echo $pic_name;
2 w9 ?0 z1 F0 X$ G/ G - echo "||";
$ d0 ]* x, v/ s9 J! J- w - error_reporting(0);
9 X t8 w* p7 S. _: Y - mkdir("images");
5 H& D6 [$ }. J0 [( x - $handle = fopen($pic_name, 'w');. \, f9 {0 F. U7 O
- echo fwrite($handle,file_get_contents($pic));
5 B' _: \3 }% h1 s2 F% F. \8 H - }
) f5 a# C) p. R9 q" @% n - 1 k8 J" u. J' w8 q
- $title = $_POST["title"];/ ~6 ]' ^" E6 Z4 u3 z
- $content = $_POST["content"];; h1 M7 z( ]8 t8 b, }
- $tags = explode("_",$_POST["tags"]);
# l& v, }( g1 y& Q( p! [1 e - $cate = $_POST["cate"];2 [) ]# m- B* S% |1 {# K
- //print_r $tags;
: a+ a% h6 l/ ]. U& K - //
. i N* \9 s& }4 Z; T3 x - //* n1 `0 c/ O+ D ~" D2 o
- $wp = new WP();7 A- B7 j( y( K: g0 Q
- $wp->main();2 ~1 W! q+ Y: T$ C, e
- //2 k2 b2 C) |* Z9 R u1 w
- $my_post = array();( K4 A4 M( K5 x" `+ Q# v
- $my_post['post_title'] = $title;8 v2 G$ n; [; E2 _+ t' y( O. r. I
- $my_post['post_content'] = $content;
& w- f5 ]+ m- H! N - $my_post['post_status'] = 'publish';
" V* {% h: |8 B9 b. j* k - $my_post['post_author'] = 1;
; U/ o: g& K9 \: a+ f - $my_post['post_category'] = array($cate);
) I2 S) A+ G) p5 U9 a: e - $my_post['tags_input'] = $tags;% @% N/ H1 M6 J- k2 f/ H% d5 t: l. H- w
- //$my_post['tags_input'] = array('tag1', 'tag2');8 `+ r2 Y! U& @& y' c$ {
- //$my_post['post_status'] = 'future';" D' S0 Z0 q. B! G* X. k& w! g
- ////$my_post['post_date'] = '2010-07-04 16:20:03';3 Y. V1 E8 M* j1 d* f/ Q
" Q, k: m1 V+ i, @0 S- // Insert the post into the database3 H: j0 G2 o# S0 h
- $ret = wp_insert_post( $my_post );
) q: H7 [7 z7 S( E' u2 ^ - echo $ret;/ V9 D) k5 e4 m( M: h
- ?>
6 F1 x$ }) ]0 [6 t
复制代码 我自己写的
( C2 l6 O2 G8 n% e- N2 Q插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|