|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
2 X% `2 z8 Q+ U! l R6 q' j
+ @, n- w( T4 _+ D7 w$ _% x直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
9 d# E. l& X; C
+ U& x8 c. _6 P1 y, x我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
1 b5 b5 U6 t* J* Y- ?
4 h2 u9 v5 `6 S, p, Z# M方便实用 简单 何乐而不用呢
8 \: J* j- A: H: F9 }3 b- <?php
; }, ]% f7 f* j
$ K& K7 b% a6 L+ c: T# O/ E- define( 'ABSPATH', dirname(__FILE__) . '/' );
, J/ U" B5 U$ f7 f) E - require_once( ABSPATH . 'wp-config.php' );% e9 O! W8 n W# S( E
- require_once( ABSPATH . 'wp-settings.php' );
/ F7 w1 Y* Y, n" V - require_once( ABSPATH . 'wp-includes/class-wp.php' );
2 w2 h1 x6 p5 f/ Q! f - require_once( ABSPATH . 'wp-includes/functions.php' );
! {0 k( O3 ?+ ^* r0 O( g* x - require_once( ABSPATH . 'wp-includes/plugin.php' );
, o0 F: r K2 L' g5 d" F. V* @ - $title = $_POST["title"];) {0 t4 V" \$ k) S' q- D' n
- $content = $_POST["content"];$ F6 Y [$ K# k- u/ J. ?9 u
- $tags = explode("_",$_POST["tags"]);9 F3 j% d9 x3 I( o" c6 V3 p
- $cate = $_POST["cate"];
5 v& l2 S8 R( O. @7 q - //print_r $tags;1 ]! z }5 g5 S9 c; r, E
- //* M; @' A$ A( z, I* {2 G* d
- //) m: ?* P# `+ F; F, B- a
- $wp = new WP();: _* p7 b; i* ~ L6 u* J2 [
- $wp->main();. N) s! G3 _ ?& S
- //. u' L6 W" |/ [+ d
- $my_post = array();
1 \+ v. Z( J/ d; H9 @' G - $my_post['post_title'] = $title;
1 \, k' L% V3 \2 L - $my_post['post_content'] = $content;
) |% q* q4 u# g - $my_post['post_status'] = 'publish';% y# \! o8 G9 V8 o$ |
- $my_post['post_author'] = 1;
h6 M x+ v. E8 b% p6 l) G - $my_post['post_category'] = array($cate);) v& K6 t$ w* C" ?$ h4 b+ k6 d2 `
- $my_post['tags_input'] = $tags;
. `3 U: J8 r' ^ R3 K - //$my_post['tags_input'] = array('tag1', 'tag2');
5 q' l+ O" z# Y% s( Z) f3 ]) s - //$my_post['post_status'] = 'future';8 }$ G+ ?& ]7 G3 Z, h
- ////$my_post['post_date'] = '2010-07-04 16:20:03';; {4 E1 Z1 P) p* j
. u p# `* I0 j" v4 T- // Insert the post into the database8 o) W$ e0 ? p' z7 r
- $ret = wp_insert_post( $my_post );! i, f4 U- j2 n7 |
- echo $ret;# y0 ~2 t& @# `; a' `
- ?>
# b ?' c9 I B4 g; h( S& _/ L
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
- c% s* `& i% k# C* u* V- <?php
. U# p9 {! v" s [9 s; a - define( 'ABSPATH', dirname(__FILE__) . '/' );' y d% q* v. @" z
- require_once( ABSPATH . 'wp-config.php' );
5 n% r+ g. v$ z4 T* N2 G4 I - require_once( ABSPATH . 'wp-settings.php' );
# m' p3 h2 n; R* I, I - require_once( ABSPATH . 'wp-includes/class-wp.php' );
[0 i5 E. k& L5 c4 a" u( M - require_once( ABSPATH . 'wp-includes/functions.php' );& T' x6 U6 B% \* p7 k
- require_once( ABSPATH . 'wp-includes/plugin.php' );
# w! z$ U+ s' R' X - $pic_name = $_POST["pic_name"];& ]9 _% j( n) E" Y# ~, t( k; R& O
- $pic = $_POST["pic"];
% W2 i# l$ {8 M. f" d: C8 ] - if($pic != "" && $pic_name != "")
5 c+ M4 T+ a) ]3 Y" j: Y - {' H# C# B. A9 y( Y* U) k
- $path = "images/";0 [/ a* |) ]) G# O+ d
- $pic_name = $path.$pic_name;
7 Q3 t/ {# I m( a# L - echo $pic_name;
5 l: S6 w- `% U1 d8 |0 L) | - echo "||";
8 ^( N/ y; U- C; I6 M$ h) k: O; } - error_reporting(0);
5 E! S" g, r' U+ q* T* _& V - mkdir("images");. r- I7 H4 G+ ?' C: O# u* ^
- $handle = fopen($pic_name, 'w');9 A; x$ q0 q2 u h* z8 C& w1 `
- echo fwrite($handle,file_get_contents($pic));9 Z3 P6 ?: B3 x$ }( Z& W) k
- }, }; B* _) `" H- c6 O( \! ^$ R) p
- $ n/ w0 T9 B7 x
- $title = $_POST["title"];. \4 T. M- S h7 h8 f
- $content = $_POST["content"];! C: j3 @1 c0 S# K0 c
- $tags = explode("_",$_POST["tags"]);
& w6 D# d5 L% |0 B" s5 _$ w) q1 F - $cate = $_POST["cate"];3 e3 p" V$ a& k9 \
- //print_r $tags;+ o& O k6 l0 ]4 W
- //) Z$ H9 }( j! |: w ?/ v U: d
- /// i" P, z7 h/ O" c* `
- $wp = new WP();
6 m0 s1 c$ L% y; J" G* z - $wp->main();, } m) b3 Q) F* ^: i
- //
% v+ Y7 c4 `# B+ h2 Y - $my_post = array();- h* [5 J1 j L
- $my_post['post_title'] = $title;: @8 Z" Z6 G: \" Z' O( P8 w
- $my_post['post_content'] = $content;
+ M7 }' h1 v. W, y* [ - $my_post['post_status'] = 'publish';
" k& ?6 n- g' i0 |' t& \ - $my_post['post_author'] = 1;
+ A+ M6 V9 j5 C% C3 f- U - $my_post['post_category'] = array($cate);* U. ~! ]# v9 T2 }) y* N8 S, G
- $my_post['tags_input'] = $tags;
% C5 D' ?& K0 n: p" j5 G" X# j; i - //$my_post['tags_input'] = array('tag1', 'tag2');
5 s( O0 {) e0 o' G - //$my_post['post_status'] = 'future';1 Q' K6 J/ \' l$ f6 ~% H4 L
- ////$my_post['post_date'] = '2010-07-04 16:20:03';0 ]8 u5 V7 e$ n7 x
- * Q7 t2 |/ X1 d0 Q
- // Insert the post into the database/ |7 ?( ~* j* C8 l
- $ret = wp_insert_post( $my_post );' p$ l. k' {7 J! Z, t) l7 @( @6 O/ {
- echo $ret;
, S/ N0 ]7 M8 n+ l5 k S/ x - ?>8 F- Z1 J" h. P! }" q
复制代码 我自己写的
" b+ Q7 A: S% E插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|