|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
9 B6 |* g* V8 Z7 w( s9 H/ E3 W, R; ~8 \0 s5 }
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
8 Q3 H5 V' Q! a- }! r) w' z/ p% t3 f8 a* h' a5 z
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
; x0 S8 b8 T! i1 N/ w$ G0 y% A
2 {4 k2 B) k9 k3 J方便实用 简单 何乐而不用呢- ) i& \# y1 g C, d9 b% [
- <?php1 Z" K6 @* J" [, y/ q4 I8 B* G& }
; V! d$ ]8 Q% }( m2 V- define( 'ABSPATH', dirname(__FILE__) . '/' );
5 {1 s+ b j6 M' |5 p$ M6 | - require_once( ABSPATH . 'wp-config.php' );, C9 k+ ]. [0 `' |, J
- require_once( ABSPATH . 'wp-settings.php' );
" J7 @; a# K# {: ^ - require_once( ABSPATH . 'wp-includes/class-wp.php' );* e5 H6 H% G9 ?, \* {- q1 A
- require_once( ABSPATH . 'wp-includes/functions.php' );/ X' @; O5 B/ m
- require_once( ABSPATH . 'wp-includes/plugin.php' );
; w4 ?7 A: Z9 M8 |6 l - $title = $_POST["title"];
9 {/ k; W1 u7 I( |. N1 Y8 B - $content = $_POST["content"];7 V$ U$ Q' U% C: W. v7 G* D
- $tags = explode("_",$_POST["tags"]);
7 ^% Y; ]; D+ A! | J0 r1 K' s - $cate = $_POST["cate"];
( {; g* X9 y& c4 R" F3 H - //print_r $tags;0 V& E% }! y( y: f6 n% B
- //4 `" W1 C# U! l* }- O5 R
- //
' W5 h! I* N1 s* P# j - $wp = new WP();# i$ F! g* q- V2 }
- $wp->main();
1 Z' S" s8 F" S6 I8 e - //
4 }5 d1 X4 I" o0 ^' x9 U; P; x - $my_post = array();( l1 Y$ {0 d2 ?1 @( ?* a8 w& I9 b
- $my_post['post_title'] = $title;
H) \5 M x( w# U) h4 } - $my_post['post_content'] = $content;
" @( i; [, t, e' E6 k - $my_post['post_status'] = 'publish';
$ o) Q% s4 r" i7 R: r! n( ?: z/ Q+ s - $my_post['post_author'] = 1;
! |' i0 y+ j- e3 b6 k. W - $my_post['post_category'] = array($cate); j' k$ b* C! x+ i
- $my_post['tags_input'] = $tags;; a$ w' k3 {% W- S. P% t3 S& h9 |
- //$my_post['tags_input'] = array('tag1', 'tag2');' P+ J3 K1 j* m& H# d; O1 O
- //$my_post['post_status'] = 'future';
2 @& K8 U1 m5 h R - ////$my_post['post_date'] = '2010-07-04 16:20:03';
* F9 h; x' v2 q) a1 V1 y" k9 }5 ?
7 n T, X/ s" ?- // Insert the post into the database
4 z4 R& \/ B8 p3 X0 e( J- _' i - $ret = wp_insert_post( $my_post );- Z0 l5 Q; A7 K9 }
- echo $ret;5 Y! b9 j: j5 s5 p' ?8 M! ~- T( L
- ?>- R/ w* R+ l9 {2 l2 K. ~
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
" _9 ?! N9 ^6 O- <?php
; p: Y& q" c/ L7 s* { - define( 'ABSPATH', dirname(__FILE__) . '/' );
5 D( W$ S: J+ Z3 n - require_once( ABSPATH . 'wp-config.php' );; ?" W! X4 J1 r8 G4 \; }
- require_once( ABSPATH . 'wp-settings.php' );
; b, Y& z% j5 }' I - require_once( ABSPATH . 'wp-includes/class-wp.php' );
. q$ i3 U1 l- c8 o9 F - require_once( ABSPATH . 'wp-includes/functions.php' );+ X/ t3 W& ]; M6 E+ T7 _
- require_once( ABSPATH . 'wp-includes/plugin.php' );
! Y+ N# J- m) z* X- s6 G; Z) e! X - $pic_name = $_POST["pic_name"];
$ S$ T2 ~4 Z1 N1 U- `% o2 I - $pic = $_POST["pic"];
* {+ \3 p# x1 L6 ~+ _. a - if($pic != "" && $pic_name != "")) |0 r# q5 K- d/ b' d
- {1 v* q# U5 K: `' p: t/ W0 h
- $path = "images/";: U: R0 E% O9 R1 n6 |; l. ?
- $pic_name = $path.$pic_name;7 x) @0 P% T2 F& r7 \1 `
- echo $pic_name;
! l6 B2 T B" |9 ^ - echo "||";
0 Q- i5 _0 c2 W- Z$ o - error_reporting(0);1 G( ?- R1 g1 p$ |/ }
- mkdir("images"); s* d1 A2 X O: Q X8 G+ h/ T
- $handle = fopen($pic_name, 'w'); E, k9 ~1 j$ w+ L* F; {
- echo fwrite($handle,file_get_contents($pic));
+ d% ^8 R3 T/ z - }; v1 K; x. k. g D7 }4 D, p1 X
- . u2 u3 u1 x+ X# Y e9 e6 f
- $title = $_POST["title"];
5 }: w! t3 H. } m - $content = $_POST["content"];/ |- t z" ?$ y5 r4 T
- $tags = explode("_",$_POST["tags"]);' j% o$ B' T, O K0 O4 N" H
- $cate = $_POST["cate"];3 Y7 w3 Y) |7 G m: g( c4 u
- //print_r $tags;
! ]7 {0 F+ W ~1 L3 U - //
2 S; S6 \, c+ Q, ~9 C - //% q* Z h/ \* C' M( a
- $wp = new WP();
/ L) \) _6 ~8 L7 y. l6 P* ` - $wp->main();$ ? v4 c% ~, F6 k- { e
- // Q7 B: W6 P" S
- $my_post = array();
1 J6 h; J1 a3 b - $my_post['post_title'] = $title;0 \" L% Q9 m* {) L
- $my_post['post_content'] = $content;3 @2 K: F, k" y% v! {) t; a3 M
- $my_post['post_status'] = 'publish';
5 R3 t- A \0 K6 G+ d& f1 E - $my_post['post_author'] = 1;
/ s& U. Y& ?- n4 B# r* [9 \ - $my_post['post_category'] = array($cate);
- A& ]9 x6 ~# V - $my_post['tags_input'] = $tags;# o& _0 q1 m) C) B1 L
- //$my_post['tags_input'] = array('tag1', 'tag2');
3 {1 B. B4 x0 x, | - //$my_post['post_status'] = 'future';& S, h1 N) z, G( ]3 Z
- ////$my_post['post_date'] = '2010-07-04 16:20:03';, }6 C6 G0 m" }% f$ X, c7 W/ Q
- 9 Q1 R( Z) \0 ~
- // Insert the post into the database% p0 F: v4 m0 Z; f3 C4 l' Y1 E( i
- $ret = wp_insert_post( $my_post );: m% |; y) |7 u: y& T
- echo $ret;
( r* A/ ?; d0 E" D/ [ j - ?>
. H% @4 S+ u1 ]4 X& ~+ D: i
复制代码 我自己写的
) B( a# m/ M5 u9 Q. y$ E) N( k插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|