|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
8 f7 @, x s5 T0 m
4 q- F- ?: V4 t% J" B直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
8 y3 p. A0 r. L+ k2 E) B3 X( N( A9 }
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
5 B7 `3 f# W: Q9 o7 W* x8 v; X
- s1 v. x. d$ ]$ O方便实用 简单 何乐而不用呢- ' l& t0 V3 d6 f+ D" p
- <?php
$ l. n N1 l) `, g! [: p - / _1 p/ K7 s7 l1 i! G! s: A# d
- define( 'ABSPATH', dirname(__FILE__) . '/' );
- E8 d1 l7 }" t, N" ] - require_once( ABSPATH . 'wp-config.php' );4 B* J. D) J( `& t4 h7 j$ i# z0 F- T1 g
- require_once( ABSPATH . 'wp-settings.php' );
( T1 f( a2 B' Z* T1 x" |& e D - require_once( ABSPATH . 'wp-includes/class-wp.php' );3 ], L' S" {3 z( P) K# X
- require_once( ABSPATH . 'wp-includes/functions.php' );9 m- |# d6 d8 f4 U) o2 Q$ ^
- require_once( ABSPATH . 'wp-includes/plugin.php' );$ i+ \1 F. K* F9 H
- $title = $_POST["title"];0 a0 ~; n, b6 o
- $content = $_POST["content"];
& I# V+ ^% {4 K* P$ t: B$ o- C - $tags = explode("_",$_POST["tags"]);
' M6 T( {; U0 I: D9 m1 ]& C - $cate = $_POST["cate"];3 U$ ?+ s; {% f0 d- B. x+ o
- //print_r $tags;
3 I2 j) |2 x' s9 i( ~! ? - //) K7 `. f* m8 q! Q: k! n( x
- //) D( M# j$ d) j2 N' D
- $wp = new WP();: H' I! S: c2 L2 K1 v- W* n) D
- $wp->main();5 s: b' a i% ?2 j% u, M3 y
- //
* ^( v0 p) u7 N* i- ] - $my_post = array();9 s; E. y+ H% K* t/ X
- $my_post['post_title'] = $title;, }: M8 g: |3 P( N" T
- $my_post['post_content'] = $content;
' o/ U; k3 ?8 X2 m# {9 { - $my_post['post_status'] = 'publish';) l x9 H" Z/ y
- $my_post['post_author'] = 1;
* |, l: ^- K+ J8 n8 i+ B - $my_post['post_category'] = array($cate);
5 T$ W( j1 f2 q t5 Q! {( J - $my_post['tags_input'] = $tags;
7 W/ Q7 _, W' P* B$ F' P7 `* i& C - //$my_post['tags_input'] = array('tag1', 'tag2');
0 c+ ] ?" E/ t) M9 U' _8 b - //$my_post['post_status'] = 'future';# l) G2 q& y, F5 e' M [+ d
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
0 M& w1 g: J; Q
! U$ d" K3 Z7 C' d, F- // Insert the post into the database
1 A c8 Z. W, x# d# m7 r% D - $ret = wp_insert_post( $my_post );
3 U/ C1 ?5 G! ?" X - echo $ret;# L6 K3 T' ~6 I# {" \ H
- ?>* V2 n8 w+ T0 B0 h+ s6 i0 s
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ' N: z8 [# R7 H w
- <?php
6 L! N! E2 v2 V/ a. w' l( p - define( 'ABSPATH', dirname(__FILE__) . '/' );6 G9 r! n5 [6 s7 J1 h4 d6 O4 l
- require_once( ABSPATH . 'wp-config.php' );# r6 [0 r6 h2 X% L9 c" ]' j
- require_once( ABSPATH . 'wp-settings.php' );% a" I& J" `! S0 ^! E# @
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
8 D2 }# @$ P' C - require_once( ABSPATH . 'wp-includes/functions.php' );
* r4 f8 u5 |& S, _5 T5 | - require_once( ABSPATH . 'wp-includes/plugin.php' );$ o$ E3 p4 h4 c8 ^& G
- $pic_name = $_POST["pic_name"];
2 J$ n, V( ^( ~/ ?8 d - $pic = $_POST["pic"];3 X+ P. R% x- n$ S* z9 j0 p
- if($pic != "" && $pic_name != "")* X2 {7 r1 d0 C" x3 j' ]$ ?
- {
9 p' ]# S6 p% r! u- ^9 D - $path = "images/";
/ h ^- g- D8 m0 P. h+ j8 c9 g - $pic_name = $path.$pic_name;' t/ \* x. p7 n3 o) T! E
- echo $pic_name;, V5 I- [7 u4 W# q$ Y
- echo "||";6 g' Y$ X. P+ s: p3 x
- error_reporting(0);0 E# q& i/ X3 Q( W/ e6 K
- mkdir("images");; W7 M! S* t7 {8 x! Z! v, C
- $handle = fopen($pic_name, 'w');- C2 C5 }6 O! M$ A; D2 }0 g
- echo fwrite($handle,file_get_contents($pic));
3 T; }, p( j" Q @% c - }! ]0 o& W$ W M6 ?
( j% U0 X( i( r4 [5 D0 \- $title = $_POST["title"];
w! w# N- b9 ^: R- l% D+ j - $content = $_POST["content"];
; [2 B, l7 b8 ~! W$ m5 H - $tags = explode("_",$_POST["tags"]);
3 S' p) x' e, s7 J! S - $cate = $_POST["cate"];5 N" C7 e/ @2 d4 L
- //print_r $tags;3 c0 F6 ^2 A, y( s* j4 ], x K4 K
- //* z; B( ~5 q& }, s
- //
d( F, t3 l3 X2 C - $wp = new WP();5 V, C2 L3 X; j8 W
- $wp->main();
$ v+ Y' g5 B3 ], d( J( q! S - //
7 R; ]8 H) L1 H/ F$ m - $my_post = array();6 L- k. E6 _- `1 }6 \4 N
- $my_post['post_title'] = $title;$ E8 X! ?+ [. x5 R1 p) q
- $my_post['post_content'] = $content;
# \' a' r- Y3 j, o - $my_post['post_status'] = 'publish';
/ w) [( D% K7 |, S2 o& F& Y- @ - $my_post['post_author'] = 1;
' _$ |) C# q' ~7 j. q - $my_post['post_category'] = array($cate);: F. X9 C0 o6 \8 k' u( W
- $my_post['tags_input'] = $tags;6 C( A" [0 q' U
- //$my_post['tags_input'] = array('tag1', 'tag2');6 v4 u# B) F! c5 N/ L S, J
- //$my_post['post_status'] = 'future';
! ?) l0 r! d2 ]- z( q: s - ////$my_post['post_date'] = '2010-07-04 16:20:03';! H1 d# |/ }8 [7 l+ M
- . e) Z$ F! e; Q
- // Insert the post into the database( A- X8 A3 O- C) b3 ?) Q
- $ret = wp_insert_post( $my_post );
- p, f( m3 n) | - echo $ret;
* D# y" Y* ^* b; g" }* a* \ - ?>
) f5 b q$ o& a* p. i3 T
复制代码 我自己写的
! l' \+ N; {1 v, T插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|