|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 $ ~$ f, I. i7 R, h, R" z3 Y& S R& q
" @3 b( t: p0 T* m: O, X* I
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持# d- K& R9 m( Y: e8 {" t, A! ^
# n& ^; Z+ K' q" U我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
* s9 [4 S5 D r1 j" i( n
" J8 o) V+ n; H/ ?方便实用 简单 何乐而不用呢- & p/ {" O7 G' B! E+ K3 Y$ E
- <?php
. x! t8 K1 _; j6 t Q% w4 f
) `0 `( ? P% ~4 |- Z- define( 'ABSPATH', dirname(__FILE__) . '/' );# g$ o" P0 J0 t' ?6 a: q' r
- require_once( ABSPATH . 'wp-config.php' );
# U9 C1 G' T& A2 P' n7 D1 a6 | Z - require_once( ABSPATH . 'wp-settings.php' );
; m/ p+ N7 O- W# R- w* O$ Y0 z - require_once( ABSPATH . 'wp-includes/class-wp.php' );! N7 s S! N( I
- require_once( ABSPATH . 'wp-includes/functions.php' );
0 ~' f. q" R/ ] - require_once( ABSPATH . 'wp-includes/plugin.php' );
) S/ b, O0 Q. e/ U - $title = $_POST["title"];3 M7 F! m+ c/ S
- $content = $_POST["content"];; U; Y- y: v$ g2 |+ P/ u
- $tags = explode("_",$_POST["tags"]);7 e3 A, e$ E' ^1 b9 V
- $cate = $_POST["cate"];) }7 b4 @% f: U; E4 z! V
- //print_r $tags;
- I8 x6 j( F$ ^& y$ q% k - //- n+ W, p& U# U0 Y7 ?; ]8 P
- //5 j" H2 F# I) u M
- $wp = new WP();
6 r9 f# u( s% ^' K2 A# H - $wp->main();& f3 e8 q5 E' }2 C6 r+ j+ E# J
- //! G3 v5 V; U5 N$ [5 Y9 y
- $my_post = array();) ]. s" h( m. Z% {4 P
- $my_post['post_title'] = $title;' H5 {4 `' L3 [5 M
- $my_post['post_content'] = $content;
0 e5 y- w0 [" J0 Z: C- _ - $my_post['post_status'] = 'publish';
0 \. ^. d9 ^6 Y% U1 E" Y - $my_post['post_author'] = 1;9 n7 p7 `, Z5 I6 Q/ b. q" |
- $my_post['post_category'] = array($cate);
$ t" e0 B) `8 U) y( B) } - $my_post['tags_input'] = $tags;
( ^& | U4 ]2 T! z5 o - //$my_post['tags_input'] = array('tag1', 'tag2');
& ]! ]! f6 x& i: {! R- D - //$my_post['post_status'] = 'future';
S* Z" j! N1 j( A3 j/ n - ////$my_post['post_date'] = '2010-07-04 16:20:03';
# p/ X5 ]" e3 c: T( Z - " L5 q; M3 Z8 {' x* P
- // Insert the post into the database
! H4 H. Q5 l" V - $ret = wp_insert_post( $my_post );" a+ I" t/ J( l2 d( c* q' L
- echo $ret;0 [7 ]3 v9 d* E) ^# N* X' l
- ?>% t. p9 A; w2 F$ C- H9 E8 I
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
2 i9 m, c7 w* ~, x+ n- <?php/ r J/ s: Q9 O4 S7 h/ c2 q
- define( 'ABSPATH', dirname(__FILE__) . '/' );# i1 F/ L$ c8 R- F
- require_once( ABSPATH . 'wp-config.php' );
% Y8 d0 A: H) {' Y- F4 K- Y - require_once( ABSPATH . 'wp-settings.php' );
5 O; p/ P5 ^9 ~/ p9 b - require_once( ABSPATH . 'wp-includes/class-wp.php' );
6 c V* Y) y; X" S& e- @ - require_once( ABSPATH . 'wp-includes/functions.php' ); h8 p: u: }! a8 P2 f. J" ^& |* G+ }. U
- require_once( ABSPATH . 'wp-includes/plugin.php' );( ~7 v% x9 z7 T$ r/ s/ m
- $pic_name = $_POST["pic_name"];0 U- W5 ]2 u# X
- $pic = $_POST["pic"];
( C6 n6 g {# B6 w3 X/ p - if($pic != "" && $pic_name != "")/ @7 _4 s5 A+ R9 c
- {
5 y: g' j6 k4 Z) |- v- u - $path = "images/";6 M( d2 {# ^- Y0 _; D1 G
- $pic_name = $path.$pic_name; C4 A6 \. z; g
- echo $pic_name;( h/ k( [; Y) C
- echo "||";1 G, s4 f7 D% Q
- error_reporting(0);
. F) P" H% y* P5 ` - mkdir("images");1 X% C/ j; Z! |
- $handle = fopen($pic_name, 'w');
* h3 b7 u; T; ]7 ^$ Q6 G+ ^( p0 o7 } - echo fwrite($handle,file_get_contents($pic));) S$ H6 \6 D! W6 K
- }8 k' Q5 j: J: H, [( F/ E
1 E; d8 C2 a2 F( b2 D; a6 U- $title = $_POST["title"];
& z6 i, v: P1 B9 H - $content = $_POST["content"];5 H! s3 q5 _" }- B1 P: t/ H7 h: ?
- $tags = explode("_",$_POST["tags"]);. b/ j( b6 m9 F/ e3 E2 ?( {0 ?. ?
- $cate = $_POST["cate"];9 {+ g/ h# n1 o' L* h' {+ m
- //print_r $tags;
4 |; k# ~, H( g3 J& N$ X- D - //( Q! a. B+ z6 B% q7 i# ?
- //
6 V2 M' C, p; K' x - $wp = new WP(); G" f4 z2 o+ I5 ]
- $wp->main();
% {5 e; m( Q9 D/ b4 @ - //
5 E5 Y6 I% I+ e/ A8 D6 _( J6 X - $my_post = array();
* H/ `/ w$ k2 [. g, T$ x - $my_post['post_title'] = $title;
% p5 p# U5 ~: `. [) J/ L - $my_post['post_content'] = $content;
! a7 Q) K7 F2 s; u8 t- Y- N6 Y5 ^ - $my_post['post_status'] = 'publish';
1 X; E5 @" K& R5 e* I# @( q- M - $my_post['post_author'] = 1;3 Q! |5 I9 s: e7 `6 W
- $my_post['post_category'] = array($cate);
; X9 e/ w; d: x9 U - $my_post['tags_input'] = $tags;
/ M+ D: y: n4 s( z# N6 V5 C - //$my_post['tags_input'] = array('tag1', 'tag2');) v6 P2 u' ?/ K; N
- //$my_post['post_status'] = 'future';& ^0 G& \- z" g' k
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
9 [& \0 y8 h& V# q( b
2 m5 ^) c2 R2 s- E- // Insert the post into the database- Q3 n1 L& I* M$ P
- $ret = wp_insert_post( $my_post );1 p8 h5 ?3 j+ t0 A+ N
- echo $ret;
1 o# K+ t/ g& k3 g$ P7 Z- e0 j - ?>7 t# l5 I7 S; ?7 }0 [+ m, ?
复制代码 我自己写的
5 W' Y( Z; e8 H7 z( y6 J插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|