|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
. X7 P) `9 y. ]' P5 {+ O+ C( W$ F' q! I& I2 |$ M
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
3 Z# G+ }6 r4 }- k4 x: b d
2 v! V6 X k0 c7 ^8 X; x/ D我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
; q! S# N3 o1 g* M0 p6 w! U& P7 v3 \0 e% W- a8 I# y
方便实用 简单 何乐而不用呢- 6 ^9 Q2 I6 q4 p1 a) J
- <?php9 G4 r. {- A) u* }! m( D1 N9 @0 f* I
- 6 E, g' X# X; p }# E) {
- define( 'ABSPATH', dirname(__FILE__) . '/' );( W4 I) ~( J; n# |( z4 J
- require_once( ABSPATH . 'wp-config.php' );
& A7 y1 L- N# A( p0 C: A - require_once( ABSPATH . 'wp-settings.php' );
1 u$ A1 Z+ D- z1 [, K* k" }4 n - require_once( ABSPATH . 'wp-includes/class-wp.php' );" S" Q. d# y) `/ y5 }4 y. U9 d
- require_once( ABSPATH . 'wp-includes/functions.php' );3 Q X" \* c/ ^
- require_once( ABSPATH . 'wp-includes/plugin.php' );
; H* e0 }2 E. n - $title = $_POST["title"];% }! d3 J1 G" K! b. Z
- $content = $_POST["content"];
/ `% ?; |# A& f1 k4 M7 q9 l. }& s6 P - $tags = explode("_",$_POST["tags"]);
\7 q4 i( z" K - $cate = $_POST["cate"];( ], R, J" v9 L# r
- //print_r $tags;) ^/ ?3 V; T& R9 A
- //
+ i7 X- O2 @% e6 w, b- H8 P" d - //
) S* ~$ d9 n" ^( }2 E$ P8 } - $wp = new WP();
6 G% a2 a( `( o& E; O% ]0 V' V1 F - $wp->main();3 X0 S' B) l: t* q1 b4 r! F8 x ]
- //
% ~" V( d$ B$ e$ R3 Z7 j) Y4 U+ ` - $my_post = array();
8 y% f0 |) V' t$ P5 ^* E3 [+ H) z - $my_post['post_title'] = $title;
. J I& u; z; l& W - $my_post['post_content'] = $content;
2 ^) M$ x. L; P9 x - $my_post['post_status'] = 'publish';' t7 C+ @) }* A% j, X7 M
- $my_post['post_author'] = 1;
1 o3 C6 s* Z6 D0 b" c$ e - $my_post['post_category'] = array($cate);
& T% T+ }4 w: Q% Z2 f2 w - $my_post['tags_input'] = $tags;
6 s, x, o2 y2 G/ W - //$my_post['tags_input'] = array('tag1', 'tag2');
8 f" B4 P } N8 M# Z - //$my_post['post_status'] = 'future';0 T5 x5 A5 Z2 v. |0 U. e
- ////$my_post['post_date'] = '2010-07-04 16:20:03';! Z- N( t% ~( a! |
3 ]) y9 i O. ]- p- // Insert the post into the database
; }7 R$ R6 F- m2 P4 v& d+ | - $ret = wp_insert_post( $my_post );
+ ~ _8 I$ c% t8 n8 R5 G - echo $ret;8 u A. [! p5 R9 u) }' T3 _3 R4 M
- ?>: s9 q0 G5 p! {
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
2 I! U2 ?3 _3 s9 f9 B- <?php9 `% T! ~: a4 M: b2 j
- define( 'ABSPATH', dirname(__FILE__) . '/' );
) G& C9 S' W4 U4 l8 T2 U - require_once( ABSPATH . 'wp-config.php' );
! I* ` N* w* ~' S# K4 I# G - require_once( ABSPATH . 'wp-settings.php' );! b% z7 t1 |/ [6 Z
- require_once( ABSPATH . 'wp-includes/class-wp.php' );# ^$ D; g m2 l* G W y. y1 ^
- require_once( ABSPATH . 'wp-includes/functions.php' );1 [( d- q" W* O: p9 G
- require_once( ABSPATH . 'wp-includes/plugin.php' );
' | d& ~; g9 y; r - $pic_name = $_POST["pic_name"];6 U' K8 k3 J q: s2 z
- $pic = $_POST["pic"];
/ O9 R4 K1 E% |0 b) G6 L - if($pic != "" && $pic_name != "")* X5 _$ ?. I1 R
- {& s; @: a+ m9 B- ]
- $path = "images/";' H) S7 Y$ k+ M/ Z" I, D9 \) k7 R
- $pic_name = $path.$pic_name;
( @* k9 u4 R# k7 L8 R, { - echo $pic_name;8 {! o( W5 n' `4 P0 l
- echo "||";9 d+ L$ |5 n* u& ]4 ]; _
- error_reporting(0);
% l, R P$ Q. R" ]3 G - mkdir("images");: h& j* G1 \! e% E
- $handle = fopen($pic_name, 'w');
& E: r4 f6 k5 V, B$ K8 R - echo fwrite($handle,file_get_contents($pic));
8 v& W# [" z; b( r( r/ w! K - }
& Q9 B. a% b4 K' _+ F, Y& i: z - % @5 o1 q$ N+ Y% [& p
- $title = $_POST["title"];6 q+ \ Z9 F1 L# ]8 [: U4 T
- $content = $_POST["content"];5 B, n% v( I Q5 K2 ~( D F) p
- $tags = explode("_",$_POST["tags"]);
% U# ?7 M0 Q. h' [: C - $cate = $_POST["cate"];2 x& M6 q. V3 c# x; U, I1 W+ G: g
- //print_r $tags;
$ c4 k9 {- _, O9 j0 n - //
1 P9 g, T( k e - //7 n* ^; x/ }1 X1 p$ G8 f& @
- $wp = new WP();+ ]+ t7 k( j3 m# H3 `( k/ L
- $wp->main();
8 Y3 M' C; l2 o/ p8 _5 R: j, R' W( l - //
0 K/ T7 r% H+ q/ Z( T' x4 ]$ O - $my_post = array();
4 u2 B( {& t7 _ - $my_post['post_title'] = $title;8 r! h* E, w/ \9 N) @1 i
- $my_post['post_content'] = $content;
6 A. r4 ~' A) V& F - $my_post['post_status'] = 'publish';+ Q; K8 s5 [3 Y1 o* y
- $my_post['post_author'] = 1;
# l# O1 j& L& U I- ^& f* ` - $my_post['post_category'] = array($cate);6 A# x5 m. O9 Q d
- $my_post['tags_input'] = $tags;
5 {% J: ~! O9 [ l7 u" ~$ \; f3 l - //$my_post['tags_input'] = array('tag1', 'tag2');
% B$ B( H8 ^6 |, C* }" ? - //$my_post['post_status'] = 'future'; a! |; } ?, e1 F* c6 P
- ////$my_post['post_date'] = '2010-07-04 16:20:03';3 Z6 J, ?' g9 _1 b" [) N
% V9 Z& {# z: K- x- // Insert the post into the database
8 r2 l" u, c0 }& U& P - $ret = wp_insert_post( $my_post );
+ N. f$ [% ]3 O. C: i - echo $ret;
% y e( o8 `; I3 k7 w - ?>2 t4 ]9 Z. `% f5 C- u2 i/ X2 k
复制代码 我自己写的
' E5 C7 B' E9 \5 @0 ~* I插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|