|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
2 i7 P; `) g( p
& e6 I( V, y0 Y1 k直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持5 R; W" Z8 M3 T
2 L" p; f5 w8 S8 q5 a8 z我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
9 u. |8 N3 J. a1 F+ G% L$ t4 q1 I6 |) a% |$ r3 \5 J9 I2 `
方便实用 简单 何乐而不用呢
1 Z5 _" U9 k( i6 ^- m* ^" a: y- <?php: G0 |; T: b1 V( ~# \8 K
- $ X$ ?. {$ o0 b" ], A. E- f/ \
- define( 'ABSPATH', dirname(__FILE__) . '/' );
! X8 Y/ m" |: ~6 G3 | - require_once( ABSPATH . 'wp-config.php' );
- A$ J9 U2 J# T* ~1 R - require_once( ABSPATH . 'wp-settings.php' );
' w( f r: [- R( k! F& h - require_once( ABSPATH . 'wp-includes/class-wp.php' );
, Y1 ]7 E F6 g" x$ @ - require_once( ABSPATH . 'wp-includes/functions.php' );; C6 w" s6 | I% z; p: @, s) I
- require_once( ABSPATH . 'wp-includes/plugin.php' );; m! {! I0 Z9 t/ ~7 ?
- $title = $_POST["title"];
5 u' A3 q: q- u! X$ G* F - $content = $_POST["content"];" T: m6 X9 v6 O8 z: E X: O
- $tags = explode("_",$_POST["tags"]);. Z( z. n! T: p) I" g
- $cate = $_POST["cate"];
}9 i2 {6 _. Y1 @ - //print_r $tags;
2 W1 c* w9 Z- x - //" V1 I- Y' g4 Y$ t% w# B
- //
. N" G8 d; b( R+ d, l - $wp = new WP();9 y0 ?/ G8 `1 f
- $wp->main();
/ s& H. A$ Z5 z* o+ n - //
2 L# W8 a p+ F" o, J* V1 u - $my_post = array();$ `8 `& C4 M/ K( y$ e2 a- p
- $my_post['post_title'] = $title;8 I2 }/ l5 A8 Y c
- $my_post['post_content'] = $content;
8 `7 s; ?( u9 X7 ^* {; ] - $my_post['post_status'] = 'publish';
6 T" C0 p T; q6 d C& i! k, Q - $my_post['post_author'] = 1;
! F' @% U* w# b. l( g3 J - $my_post['post_category'] = array($cate);$ S3 X; n7 B) Q' e
- $my_post['tags_input'] = $tags;
9 z# e ^6 k0 A( B) v$ X( k5 b+ ` - //$my_post['tags_input'] = array('tag1', 'tag2');) |$ d. f* l8 a h1 o! e# v# h0 R
- //$my_post['post_status'] = 'future';
) ^9 h% d1 h9 F( h/ x - ////$my_post['post_date'] = '2010-07-04 16:20:03';0 K8 V) f( B& [) S1 C- E
- $ b$ d6 _2 h4 t) [& L! ]& }! G& m
- // Insert the post into the database
7 m4 h& g) U8 @8 | - $ret = wp_insert_post( $my_post );, ^+ |3 T, V% V$ i U, n) |- C
- echo $ret;. d0 N* c* _5 k% c2 t- a
- ?>
/ N( w/ n2 o8 Z& P$ W* S8 s
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
0 N( h( g$ f- o% f- <?php. ]* Z1 s: R: G- ^9 d
- define( 'ABSPATH', dirname(__FILE__) . '/' );
, {. w- G: _2 \* P. a0 H - require_once( ABSPATH . 'wp-config.php' );
# X; n' s. a$ i7 R5 t" l8 o+ k - require_once( ABSPATH . 'wp-settings.php' );9 ]. e3 E4 Y- Q8 @$ `1 S/ z
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
( M* _% K- N, N# }0 ^ - require_once( ABSPATH . 'wp-includes/functions.php' );
6 Q; `4 b0 L6 _ - require_once( ABSPATH . 'wp-includes/plugin.php' );' Q) H4 G$ o Q7 k6 A- J
- $pic_name = $_POST["pic_name"];1 ^% \) S' ]; U. g
- $pic = $_POST["pic"];
. N7 r- v2 x* g8 |9 z1 t7 ~9 l - if($pic != "" && $pic_name != "")
7 _3 v7 Y' A- h V1 C4 ^ - {! l' C8 Q; Z* U9 V# s) o, A
- $path = "images/";
) E8 A' k% O: N# ?0 X - $pic_name = $path.$pic_name;
- U& Y" }" F( Q4 d2 ` - echo $pic_name;# ?$ W+ L+ e# N
- echo "||";1 {6 Z; Q# c. E
- error_reporting(0);# T9 o' `# O" M
- mkdir("images");
! ?+ G3 n F; c- z* R* W - $handle = fopen($pic_name, 'w');
8 m% W" T3 E' r* K. G8 }. Q# ? - echo fwrite($handle,file_get_contents($pic));
! b2 u+ ^# @: z+ X - }. i( M6 C" s# v* O
- ) z. }. U2 R/ t/ O% t/ T6 u9 S1 ?
- $title = $_POST["title"];
% i, }* M6 k7 F: H! e& m5 {' r& l - $content = $_POST["content"];5 a% J; a5 K+ p8 E; t3 L
- $tags = explode("_",$_POST["tags"]);
I( @# v# j- f5 g5 p8 [6 W - $cate = $_POST["cate"];
& }. F: B# D& p# a; A9 o, O3 i. Q - //print_r $tags; o0 s, _, Q5 E0 b' \
- //
/ i5 W' y- @' e) j0 I - //; }; i2 x! \5 I1 Y0 c/ e7 q/ T* I3 T
- $wp = new WP();& U8 a+ J6 S% a* c& q0 L% h2 B
- $wp->main();
1 h4 @; w/ s( w a - //5 d" u: X* f/ T/ k
- $my_post = array();
E% k, |8 r4 J9 H0 L* U( W2 [8 I - $my_post['post_title'] = $title;
6 u/ e, \/ P% j9 R2 h - $my_post['post_content'] = $content;- P- T; M) x5 a+ N# M
- $my_post['post_status'] = 'publish';
( ~6 t% l. D( h" Z - $my_post['post_author'] = 1;
& Q7 f) _3 C: a - $my_post['post_category'] = array($cate);, n/ p- T( S j% H+ o0 o& r1 Z
- $my_post['tags_input'] = $tags;
% e4 m7 h! \: j - //$my_post['tags_input'] = array('tag1', 'tag2');5 h- E% r2 v$ K6 T3 p- o
- //$my_post['post_status'] = 'future';
3 m& y5 b9 z ~& Z( U - ////$my_post['post_date'] = '2010-07-04 16:20:03';
2 ~% I7 G7 \0 A9 k
3 P: Z- `. O8 u- // Insert the post into the database
' { S! i; } q1 H - $ret = wp_insert_post( $my_post );
9 n4 F: [/ X1 x$ k' d - echo $ret;( ~$ _7 c5 r- d6 w
- ?>5 o& Z! _: z: P$ g4 C
复制代码 我自己写的
" Z) T# P; d. T. [+ J插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|