|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 6 W! ?% U- j4 k, [
T) j+ P8 `. Q直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持4 F) _, w+ }8 k2 @
9 K' q4 G% A7 b, v+ `3 D a$ [5 l
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
9 t p7 `+ d8 {1 w. a
; ]9 s0 E5 s( r5 B; }方便实用 简单 何乐而不用呢- ( K) N7 U: ^; A) h. Z5 |! u1 N
- <?php' P/ m/ g* M- y1 Q2 J% |* i; a- c: F9 R
- 9 U& Z2 ~: u( W! g' b- g! _, T
- define( 'ABSPATH', dirname(__FILE__) . '/' );8 L( E& n1 s s' C. c- Y! Y
- require_once( ABSPATH . 'wp-config.php' );5 e5 @ b# Z- K
- require_once( ABSPATH . 'wp-settings.php' );
* a1 U6 Z+ H3 T4 t1 N" A - require_once( ABSPATH . 'wp-includes/class-wp.php' );9 E' N1 J ?: `. S0 }: ^
- require_once( ABSPATH . 'wp-includes/functions.php' );# [& v4 i* {$ Y4 }5 I4 B
- require_once( ABSPATH . 'wp-includes/plugin.php' );
1 u: U9 W) j" n( C' c - $title = $_POST["title"];
% p$ q8 W, Y% c' W - $content = $_POST["content"];( b7 P. g; i6 ~. L. L1 X
- $tags = explode("_",$_POST["tags"]);1 z3 e" k1 ]5 u9 i2 e* P0 Z
- $cate = $_POST["cate"];0 T6 j$ w+ U$ Z0 W5 I
- //print_r $tags;9 S+ V, j* t/ h+ ^. c1 n0 H/ @ R
- //5 V8 L7 E- g% R- t% [
- //- ~/ a# t# s" h
- $wp = new WP();! V& z }8 j( D
- $wp->main();
* m0 L/ Y5 H5 o3 \* N$ I - //
; d0 {9 l1 b; l. Z, e' g) w) x - $my_post = array();
5 K' u5 h: j N/ |) o - $my_post['post_title'] = $title;
. B& Z. a; [) j2 Z7 P - $my_post['post_content'] = $content;- t- T/ O: Z( a Z' t, \) E" ?
- $my_post['post_status'] = 'publish';4 {9 P& j( i* P! Y5 T% \
- $my_post['post_author'] = 1;+ t% K* I% {4 H; D# Q$ U' o* ~, f
- $my_post['post_category'] = array($cate);
) B8 {6 c% K8 O: ~( E2 x - $my_post['tags_input'] = $tags;% ~+ {7 L; X/ A7 `
- //$my_post['tags_input'] = array('tag1', 'tag2');/ ?, Z" T8 m+ K$ B5 w
- //$my_post['post_status'] = 'future';
7 O0 X; ~( z, S( S6 r" S$ ? - ////$my_post['post_date'] = '2010-07-04 16:20:03';
: Y ^" T, C: z7 u - [ K, P- u7 X4 \5 ~$ n" `
- // Insert the post into the database
' T& l3 E- v$ Z, @$ }( }- S - $ret = wp_insert_post( $my_post );
1 G1 i# j' z- x/ V" K; Q% j5 Z - echo $ret;
7 e; V, U8 |8 E+ E% O - ?>" ^. z6 t- u9 x
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 0 ^& h8 I" L% N: `8 n
- <?php
& D* H( o& q x- p - define( 'ABSPATH', dirname(__FILE__) . '/' );
$ Y/ t/ }" @0 i/ ~ - require_once( ABSPATH . 'wp-config.php' );
3 s- Y; s+ V: c - require_once( ABSPATH . 'wp-settings.php' );* o* Z& K6 P3 N3 R
- require_once( ABSPATH . 'wp-includes/class-wp.php' );1 q |# P. h/ S2 ]3 U! M; d; K
- require_once( ABSPATH . 'wp-includes/functions.php' );
# e& g0 d4 N: H5 h: |* I - require_once( ABSPATH . 'wp-includes/plugin.php' );/ e: R; K& W+ c; t: b
- $pic_name = $_POST["pic_name"];
5 o0 i g+ O& N - $pic = $_POST["pic"];6 x6 P% m( e) `" S5 K6 r
- if($pic != "" && $pic_name != "")$ m. m4 S9 G$ v+ l9 ~" W( J
- {
/ U6 E0 `' E( p n4 D - $path = "images/";
% u( J* z6 {* y- l; d - $pic_name = $path.$pic_name;
1 A o+ z: ~" x% k6 D' n - echo $pic_name;. E7 c0 \* {$ T- W; L
- echo "||";
7 s3 @' X) B# a n; ^- `: L D - error_reporting(0);' S5 o* t; z2 L& N% Z3 M0 Z! r: Z
- mkdir("images");6 j9 L$ q# I! d
- $handle = fopen($pic_name, 'w');
; V5 g% c, D4 ]# _1 M& {( p - echo fwrite($handle,file_get_contents($pic));- [! G/ e& O- L
- }
. y N' {0 m1 G8 w' K, [9 R3 a9 d
3 D1 N/ i& F% s [ k, v9 D- $title = $_POST["title"];+ B. Y9 X6 Q* E/ o" s
- $content = $_POST["content"];
9 G4 l5 C0 \1 X9 T# s9 ^ - $tags = explode("_",$_POST["tags"]);
. e- V5 Q0 s$ { - $cate = $_POST["cate"];1 Q+ G4 x3 J6 Z9 R* w
- //print_r $tags;1 V& T9 r5 s1 N
- //
# g6 J3 \3 X/ W* ~+ `/ h/ U w - //5 V6 b1 G1 S$ ?
- $wp = new WP();( J0 c1 l" ?3 t; m
- $wp->main();7 j3 v9 h( f; l; t- c( @3 V3 [( g
- //
7 R: A: [9 y7 q' c - $my_post = array();
) B/ P/ N: ~0 s; A1 d - $my_post['post_title'] = $title;1 l' d& p# P* L/ X. H4 d( X
- $my_post['post_content'] = $content;8 K. g/ b& K- h) u
- $my_post['post_status'] = 'publish';: r1 T) ^9 f: D5 |; T, `2 V4 X
- $my_post['post_author'] = 1;/ @( [+ H) e& z3 P v w3 A$ S
- $my_post['post_category'] = array($cate);
: U/ g% j4 z- N! B5 A0 X- M - $my_post['tags_input'] = $tags;. X& r! i% @. ?, f' Y! x
- //$my_post['tags_input'] = array('tag1', 'tag2');! Z2 s" w7 J5 s5 \8 r) K
- //$my_post['post_status'] = 'future';
; ^- u/ d& A0 z7 C! X. _ - ////$my_post['post_date'] = '2010-07-04 16:20:03';
5 o. v) f% n! J8 m4 X' o# g - " ], ^/ ]/ Q, S
- // Insert the post into the database
" V! w% A8 B- z8 g" R! g, o - $ret = wp_insert_post( $my_post );
- @: [' b8 F2 V/ M - echo $ret;7 x3 @5 F0 ?; |/ Q5 |! D
- ?>
1 I8 U* S9 B) _0 W% \7 f
复制代码 我自己写的, |: j, q# l5 e# u2 F8 _
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|