|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 . _* ~- y' ?/ W. p! T2 f
) s4 t1 P; \: ]! r直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
. `) v& Z9 J* D5 x f! v
- d: K0 }: s [我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
: T- v& w5 n1 n; K' @3 `9 m5 g! x+ b) }
方便实用 简单 何乐而不用呢- - N) ~3 h( q. m* P
- <?php
- k0 S `) K. e - & o6 i% ]) B- n+ I0 j. U2 }
- define( 'ABSPATH', dirname(__FILE__) . '/' );' ^4 _* C. }5 l j5 a" _
- require_once( ABSPATH . 'wp-config.php' );
0 [+ ] S- U b# r3 x, Y - require_once( ABSPATH . 'wp-settings.php' );) y" J* ~4 S# X* H6 Z! P
- require_once( ABSPATH . 'wp-includes/class-wp.php' );7 a4 ~& E0 S2 y A/ M; [
- require_once( ABSPATH . 'wp-includes/functions.php' );
" h& y- A& j4 n' @ - require_once( ABSPATH . 'wp-includes/plugin.php' );- T3 K0 B2 O( M6 ], F& B) }/ `( L
- $title = $_POST["title"];' u+ r" o& |2 G& y. V+ a
- $content = $_POST["content"];
9 i9 n8 }( C5 A - $tags = explode("_",$_POST["tags"]);
* b' M& F; ^, S% b$ S3 l7 @ T" T - $cate = $_POST["cate"];( d& f- A: T4 P/ C. ?% ^% Q8 ~- y
- //print_r $tags;3 j# a, I6 Y4 U& W3 I6 i' y
- //
! g7 C+ Z; R" e$ ^! W - //
+ K9 h* M; i c! O2 z# ^& Z - $wp = new WP();2 D. J% @1 H' m/ l8 v' ^
- $wp->main();$ R, ^: ~" \" s+ q3 @. S0 _
- /// J9 m2 ?# }: _$ a: x
- $my_post = array();
6 v$ S2 i4 z$ Y4 W& r" q - $my_post['post_title'] = $title;9 X6 }# k v. h7 g2 Z x
- $my_post['post_content'] = $content;
2 v( x; J; c. A1 L) C. {5 I$ [% S- f - $my_post['post_status'] = 'publish';# ^/ M5 \( n+ i7 a! ]4 N) \7 c& e' K
- $my_post['post_author'] = 1;
" [) R" k/ Q! E/ K' X [ O - $my_post['post_category'] = array($cate);5 R; r# f2 f9 X) |
- $my_post['tags_input'] = $tags;8 y5 M0 v: ]& p y/ \
- //$my_post['tags_input'] = array('tag1', 'tag2');
$ y8 s) {& Z+ t5 a: q2 \ - //$my_post['post_status'] = 'future';
5 f7 r2 G: f8 n a# _9 r9 J# E8 ~ - ////$my_post['post_date'] = '2010-07-04 16:20:03';& h& g7 l4 B/ H% X. |) S
9 u8 U# f' Y( W' e8 d) z- // Insert the post into the database+ s$ J; q% ?2 \2 W
- $ret = wp_insert_post( $my_post );
( m" o! j7 |9 I5 p* R5 {" b - echo $ret;
- \2 b) a) z- @8 R8 F - ?>
8 D" P2 O) ^6 O r* K5 l
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
2 e2 w0 S* W7 C6 i1 x0 J- <?php0 B* P; T! Z8 R( t2 Q- p
- define( 'ABSPATH', dirname(__FILE__) . '/' );
" W/ d2 ^1 i9 m3 L - require_once( ABSPATH . 'wp-config.php' );/ X* N1 q Z6 ^
- require_once( ABSPATH . 'wp-settings.php' );# z+ U. {" j: G$ X* M* z
- require_once( ABSPATH . 'wp-includes/class-wp.php' );- V0 ^* \1 \9 O1 @* N8 W
- require_once( ABSPATH . 'wp-includes/functions.php' );
& P" m; o, M2 j" w$ X - require_once( ABSPATH . 'wp-includes/plugin.php' );
/ d) w! e5 @! y& I. c' t# `% K - $pic_name = $_POST["pic_name"];
* I& ?+ |- s; w# ~3 L3 \# H# S. Y - $pic = $_POST["pic"];( w3 v6 z" X, _4 Q1 S" D
- if($pic != "" && $pic_name != "")
3 [) A C+ A$ H( c - {
* c6 g5 u* V& i' S, A$ B( e - $path = "images/";
# E' _1 [: u6 [6 U3 E - $pic_name = $path.$pic_name;" g9 w9 S1 m$ l
- echo $pic_name;7 M# T/ W# P+ ]5 s3 ~
- echo "||";$ Y4 y8 d. G' h6 Q+ N2 G9 y M
- error_reporting(0);$ A$ N- p% v4 C# } t/ f* Z! {
- mkdir("images");
- f0 y/ a1 o) a+ V+ Q3 N/ j4 T& x - $handle = fopen($pic_name, 'w');( p0 k' F4 Y& ]" x
- echo fwrite($handle,file_get_contents($pic));7 b8 E3 i1 X/ P ^: J$ Q
- }7 t7 z" w" @4 r7 J G( |4 g
- " G% X! l' [' s4 A2 w
- $title = $_POST["title"];
6 b: E% M, z ~7 F) T - $content = $_POST["content"];
0 {8 s; B- _% _5 p - $tags = explode("_",$_POST["tags"]);$ Z8 P7 ^8 `* m3 [: h" @$ R
- $cate = $_POST["cate"];
+ \6 }* a: G# @% a8 w8 b - //print_r $tags;
. g U/ s, B/ u8 w - //( ]: ?) Q4 r$ D! `( u
- //
9 ]) c: Z) R3 n3 J! i+ ` - $wp = new WP();
; M% ^! i3 D9 G5 ^- H - $wp->main();" b+ q4 f q; F; w8 F' G4 c N5 w
- //! w3 M' f4 U0 x6 W0 W+ K+ b& t( C( r4 v
- $my_post = array();$ W# `* C9 x4 J
- $my_post['post_title'] = $title;, ]3 |* ]" {/ N3 s" A5 v% w; |
- $my_post['post_content'] = $content;, {$ y$ j) q) s: K3 m
- $my_post['post_status'] = 'publish';0 K* `5 P! g. y- g( h
- $my_post['post_author'] = 1;
! i2 c/ ?- Y0 ~, Y0 s - $my_post['post_category'] = array($cate);
( c7 D6 H! t; o# I - $my_post['tags_input'] = $tags;
& X% c( F& b. `$ Z - //$my_post['tags_input'] = array('tag1', 'tag2');: `/ N# r& f3 ], m4 W' r1 _
- //$my_post['post_status'] = 'future';
/ G& r2 V0 V6 ^" H# Z - ////$my_post['post_date'] = '2010-07-04 16:20:03';
! b# \! f9 o- T+ f - . U0 I% a! O- x$ w* d
- // Insert the post into the database
7 j: b( q- W% x: o - $ret = wp_insert_post( $my_post );
' A6 ^7 t8 K0 ^% B - echo $ret;3 S4 [" i( w, G( v( s! ~. o) `
- ?>
1 j3 d+ N& E* ~* a4 x/ ]# r
复制代码 我自己写的
4 U1 Y+ P1 u5 `2 W: ~* D6 ?插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|