|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 5 e" @* k3 W* a# e6 Z
, Q. j/ o' ]/ s# i6 y: {
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
( q1 l* l. _) W& q5 a5 o$ f! f4 J. }( z# L) ?9 g
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了0 q4 {% i9 C8 @2 K5 \
- p; i7 U8 e: @* V: [% I% V! }6 z- ^方便实用 简单 何乐而不用呢
4 O. y# s6 ?" ~+ U9 t3 p0 a' \3 ~" X k+ y- <?php% Q+ L K; P; S$ }1 N
- . f# d) g1 z- X0 _ I8 g# @
- define( 'ABSPATH', dirname(__FILE__) . '/' );8 N& @ d: w" f: ^+ J
- require_once( ABSPATH . 'wp-config.php' );* E, r- t u8 A
- require_once( ABSPATH . 'wp-settings.php' );% n3 n: u+ z; Z( i5 u! x
- require_once( ABSPATH . 'wp-includes/class-wp.php' );4 K. H0 [3 l1 H* c5 H5 F
- require_once( ABSPATH . 'wp-includes/functions.php' );8 ^# e2 N4 O) V1 x
- require_once( ABSPATH . 'wp-includes/plugin.php' );
! O0 c1 \8 m1 N - $title = $_POST["title"];0 ~# R7 ]+ D% w$ t3 E+ ? ?
- $content = $_POST["content"];1 k+ |9 f1 H8 I7 [ D% i4 t4 B
- $tags = explode("_",$_POST["tags"]);4 \$ t8 s% X8 X: J* n- O
- $cate = $_POST["cate"];
x0 f* |+ p" m% V3 } Q- {5 s - //print_r $tags;+ }- v2 L1 y$ [
- //$ o7 i! W: `; \8 t( G' C+ f
- //
$ D' K/ r1 u+ H# y$ e/ I j0 n7 j - $wp = new WP();
4 h! ]0 U+ x% X! l - $wp->main();
* F, T1 H* ^2 y - //5 T3 F9 t5 Q& V* s
- $my_post = array();
5 a+ G: U0 O6 e7 D S; r0 A - $my_post['post_title'] = $title;
+ b3 u4 p& R) N1 @) ?( R - $my_post['post_content'] = $content;- S7 K4 b/ f. F+ f
- $my_post['post_status'] = 'publish';/ I; H K* Z7 N2 n( ~# \
- $my_post['post_author'] = 1;
5 e& H0 }/ N+ k" g; n/ ? - $my_post['post_category'] = array($cate);
7 C( L' _. q' u3 T+ W - $my_post['tags_input'] = $tags;( o8 w. [- [. F v0 C
- //$my_post['tags_input'] = array('tag1', 'tag2');
( A3 [9 D1 s% D# T4 g - //$my_post['post_status'] = 'future';
2 H4 B3 U+ B: Q2 n. k; I - ////$my_post['post_date'] = '2010-07-04 16:20:03';: P9 M9 @0 p4 I" [# g
- 4 y; }0 s/ A% T) y9 c
- // Insert the post into the database5 _3 A6 v# V, o& b1 J x4 q
- $ret = wp_insert_post( $my_post );( E7 z/ Q( @( K+ y% v$ x
- echo $ret;
' L, B5 w" o! X+ y) V - ?>
+ Q4 N( g7 E/ m' y
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- : `( J6 l/ w1 |6 h5 _
- <?php/ Q2 D" l) r% U+ U
- define( 'ABSPATH', dirname(__FILE__) . '/' );
1 i8 y2 G& j2 C - require_once( ABSPATH . 'wp-config.php' );. F- B) x& \2 @9 Z
- require_once( ABSPATH . 'wp-settings.php' );1 q. h, S, ?. c- Y
- require_once( ABSPATH . 'wp-includes/class-wp.php' );( q7 Q' P! x; x7 l
- require_once( ABSPATH . 'wp-includes/functions.php' );% X9 X( Q0 N0 T" l( I; m( U
- require_once( ABSPATH . 'wp-includes/plugin.php' );$ ]% {, V% \' s3 Y5 l8 M2 ]2 u1 m
- $pic_name = $_POST["pic_name"];
9 h8 I/ }9 s7 E - $pic = $_POST["pic"];, v, t! F( b( J2 ?) t- C" k
- if($pic != "" && $pic_name != "")1 q7 {0 g; ^5 A
- {
% `: p- w0 m. }* f# Z2 y% D - $path = "images/";
' w$ @5 m1 W6 e( b$ r - $pic_name = $path.$pic_name;2 i/ D6 I( J2 `1 M/ T* c$ K' f2 M3 z
- echo $pic_name;" I! C/ b' b. u% O% n3 |5 D6 s
- echo "||";+ c0 n3 Z: n: {2 V# H; `, L
- error_reporting(0);% x$ X: ~2 k1 A9 H* j
- mkdir("images");6 I, w7 ]. ]( i8 ]: u/ R
- $handle = fopen($pic_name, 'w');
. U8 Z4 Z/ p# L, B4 ]# f - echo fwrite($handle,file_get_contents($pic));; Y, @1 \$ t' T2 j
- }$ f6 V& J) b; d. W
- 7 q" h1 _+ j: U2 H0 N0 y
- $title = $_POST["title"];
$ m2 z+ W8 K) X! n0 ? - $content = $_POST["content"];
/ F( Y2 j4 A- S% q/ Y - $tags = explode("_",$_POST["tags"]);5 g2 i) q' o. s# [: k
- $cate = $_POST["cate"];; u0 A4 I1 }1 m4 T5 z6 E
- //print_r $tags;7 ^2 F2 v4 G- g/ y3 g* k* X. q
- //
% m6 O3 d6 K: U! I, `& O* n7 [ - //
3 l+ Z5 m2 L; t' X3 L7 w - $wp = new WP();! O" b. t6 O, W) y% C
- $wp->main();$ e% v( W6 h% @' _' V% o. _
- //# f7 l; P: W) |2 E
- $my_post = array();
% o' ~7 W T* U4 I% l0 s, `% \ - $my_post['post_title'] = $title;( A( G4 z, [# C) y4 l0 z
- $my_post['post_content'] = $content;
! J% L0 r, Q; r - $my_post['post_status'] = 'publish';: Z% J* L4 f f! I4 B4 X
- $my_post['post_author'] = 1;
* a2 \% f5 \# e5 P - $my_post['post_category'] = array($cate);
8 G- v/ q5 a" r( @, X: ] - $my_post['tags_input'] = $tags;
" J+ ~* c- W& { - //$my_post['tags_input'] = array('tag1', 'tag2');5 W; A }! D) {& G( S
- //$my_post['post_status'] = 'future';' G2 m: p+ x* ?. g6 S
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
( a; z2 a% A& a- e* H' x
4 u9 [/ v1 @! Z5 n# u- // Insert the post into the database( o( g8 J% L4 Q: N' }
- $ret = wp_insert_post( $my_post );
/ v' V& J& M" X) T3 V I - echo $ret;
6 r$ O* f" |' H! m( F$ c# W - ?>* {5 }/ A- J* K! z
复制代码 我自己写的
( J- T) q7 f/ [& j8 x ?- J插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|