|
本帖最后由 finder 于 2014-12-28 15:13 编辑 " `; I d3 p0 |; P# }
3 w: e( c9 Y( ?* U! }( f
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
( C1 ~4 @) K9 m' B
% e+ I: }3 D6 f+ Y$ _- V我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
' m4 N! _6 y3 F" R9 I0 d8 W3 `' m. u8 i5 ~2 |) K$ X" |
方便实用 简单 何乐而不用呢
/ R/ V0 w! m4 U+ J/ c8 y' r- <?php
2 Y7 ~4 ?5 L2 |9 B7 z
1 `6 X2 O( K, d' V% m2 G: ^- define( 'ABSPATH', dirname(__FILE__) . '/' );; F7 }+ \1 V) [. G& F% C4 X3 ?$ s6 {0 X
- require_once( ABSPATH . 'wp-config.php' );" v( J# P1 w0 f# y% w
- require_once( ABSPATH . 'wp-settings.php' );
' T% W+ o. C- T4 r' a/ d: I# o - require_once( ABSPATH . 'wp-includes/class-wp.php' );
" L+ {7 \6 x+ _! v# Z - require_once( ABSPATH . 'wp-includes/functions.php' );
4 R) ^- N* x, U" W - require_once( ABSPATH . 'wp-includes/plugin.php' ); k0 d" m0 j Y: R4 O( T
- $title = $_POST["title"];& s8 E1 N! }" @8 O2 _: k( q1 P
- $content = $_POST["content"];
( z& b* M) B* n8 r" | - $tags = explode("_",$_POST["tags"]);
: e. C# m6 _, M6 q - $cate = $_POST["cate"];9 G) E4 q. o# W q
- //print_r $tags;
+ M- d% {5 Y1 w; Y. h5 E3 ?- [* w - //. I1 E) r. b1 J3 h3 R9 G' P
- //9 z! H6 [: A9 A' T* m! Q9 w! i- t
- $wp = new WP();
% d4 R$ F+ g7 J! { - $wp->main();
6 x8 M- K5 Y1 Y# ] - //
0 @5 H5 r$ H- o+ C - $my_post = array();% R( p& m6 k6 T( P
- $my_post['post_title'] = $title;
( Q" U1 t G' F5 ]( C w - $my_post['post_content'] = $content;
$ l+ O4 A4 }0 ^$ z" d8 q g - $my_post['post_status'] = 'publish';
! X$ u! `. n6 x* } p1 Q - $my_post['post_author'] = 1;
0 R- q: c4 a5 V8 W - $my_post['post_category'] = array($cate);7 z x1 Z; W7 c$ A$ ?! v' L0 w
- $my_post['tags_input'] = $tags;
, G) \3 w7 k$ m0 I& [ - //$my_post['tags_input'] = array('tag1', 'tag2');
7 }/ ~, d. y( z+ i. e: E _ - //$my_post['post_status'] = 'future';! R0 l; B+ d4 L( \; t3 x
- ////$my_post['post_date'] = '2010-07-04 16:20:03';( Y& c8 Y7 ~' ^# |' }% p2 O w% O
5 M# I) H" @9 P- // Insert the post into the database
. i* e, [2 N% ^3 f& i - $ret = wp_insert_post( $my_post );2 g* E8 ]! x) P. a3 p5 v& j* x
- echo $ret;2 t1 q A2 A8 O
- ?>& \' V8 _ m, @8 n4 a; A
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
3 x2 R- j2 a8 ~: B$ Y5 T4 g5 B- <?php
# X8 ?, F4 S; x; P# _% a4 } - define( 'ABSPATH', dirname(__FILE__) . '/' );
# v- {; M5 |* _' E - require_once( ABSPATH . 'wp-config.php' );
; ?0 N8 k$ P0 ~, k0 E' M - require_once( ABSPATH . 'wp-settings.php' );( M. m0 _9 A2 J4 i1 I$ ]/ ^
- require_once( ABSPATH . 'wp-includes/class-wp.php' );$ A9 K, G* z. ^, c( D, z' G
- require_once( ABSPATH . 'wp-includes/functions.php' );0 C9 I' L; Z: M9 E( k/ }; h: b7 t
- require_once( ABSPATH . 'wp-includes/plugin.php' );
6 U7 M9 c& e4 z* r+ z" e - $pic_name = $_POST["pic_name"];
0 u: G$ g: t9 x+ a9 `/ M7 O - $pic = $_POST["pic"];
5 |& ^! j% b) H1 A% P - if($pic != "" && $pic_name != "")3 V* R) e3 W {& }$ ]1 F A
- {' a: F1 y( S3 ~* ^& P8 r$ u
- $path = "images/";3 {0 S$ @4 [) F7 s
- $pic_name = $path.$pic_name;7 x1 T A) [, G: a6 ^# M
- echo $pic_name;: P2 K; c% r0 z' j% E5 T8 g5 g
- echo "||";
3 I) W+ Q3 o5 J' A - error_reporting(0);
. S% D6 H, j1 u' ?) v1 J1 ]0 U - mkdir("images");
/ g9 t+ Y) ~* q - $handle = fopen($pic_name, 'w');
/ R9 F0 v7 k. C0 o: O0 v' t) y - echo fwrite($handle,file_get_contents($pic));( g( L6 m1 \2 a& w
- }
j: V! q$ |+ j- P$ r2 b
0 g( w7 \0 y$ T! W- $title = $_POST["title"];" P- T9 C* S. Z4 Y$ W6 U
- $content = $_POST["content"];
0 |( @3 n( m' ?( l) x" W( e. C - $tags = explode("_",$_POST["tags"]);0 H/ l9 S, g, j( O$ t
- $cate = $_POST["cate"];
7 Z! }+ |6 O/ d4 W0 [ - //print_r $tags;
! [, _9 Z/ }9 b3 M6 E6 J* ~9 i - //6 i7 d% t' R; v! I' y) G& s; P& \
- //. s' o- W) B8 B6 |8 _$ Q
- $wp = new WP();6 ^3 G9 z5 I& m( i
- $wp->main();
0 s( _3 d6 t0 }: P) y- N7 H! p- P - //
! l( F I+ D8 V- V: z5 t# Y1 R - $my_post = array();( q! P; y5 v- M- ~( i7 Y
- $my_post['post_title'] = $title;( @+ Q1 N4 \( ~& |
- $my_post['post_content'] = $content;
& M7 m6 K% C B8 `2 A3 u) n. y - $my_post['post_status'] = 'publish';+ e* N U. ], H2 S5 I% E: V8 `4 C
- $my_post['post_author'] = 1;, B* e( ]4 t9 k# n( c/ z- N
- $my_post['post_category'] = array($cate);
) w& M0 E5 [0 F) U. Q - $my_post['tags_input'] = $tags;
& |3 v( O6 z) b- {' ^ - //$my_post['tags_input'] = array('tag1', 'tag2');
9 A+ j3 ~1 N, I' r& L - //$my_post['post_status'] = 'future';$ U* k# F1 ~2 g/ G' [
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
* _) k; [ t/ |9 q2 }8 r
) Z% {# X! y& v2 o, U# t/ L: r4 I* e- // Insert the post into the database, _7 D! O4 {! L$ o
- $ret = wp_insert_post( $my_post );
, z+ [+ B I- H, b - echo $ret;6 Z3 S( C% n: G0 U' t& N
- ?>/ K# T6 D' b# I
复制代码 我自己写的5 n7 m$ o5 _2 d" r B* y/ ?
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|