|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 8 a& |+ z9 F1 c Z+ B, s
: j/ `. _& _5 y$ H
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持& Z& T2 b% y& @, G) \% u0 ]
& Y& J3 W* [) ]2 {* |7 f
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
( O* n$ r9 P0 p1 h- \* e* o |8 U4 } L' f V5 T( M6 t6 g9 L' S
方便实用 简单 何乐而不用呢- 1 R. T3 o$ Y" o) l9 o
- <?php2 J2 U% s' Z9 {. o0 x
l' s* M6 J7 K) ~- define( 'ABSPATH', dirname(__FILE__) . '/' );0 t) F0 ]# P2 q" v
- require_once( ABSPATH . 'wp-config.php' );
5 F `7 Q2 j7 K0 W6 \2 @ - require_once( ABSPATH . 'wp-settings.php' );) @2 F9 ~. y" _$ K
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
% L( _* W# s2 s - require_once( ABSPATH . 'wp-includes/functions.php' );
; O8 D" I7 f. O' v& n% L - require_once( ABSPATH . 'wp-includes/plugin.php' );) f8 Q5 [/ v3 f( X/ r, o6 o
- $title = $_POST["title"];; C k! E- L- z; @6 t0 V% y
- $content = $_POST["content"];
% P7 J. _' E! }( `4 B - $tags = explode("_",$_POST["tags"]);" H- y5 r. E7 ^5 d1 ^
- $cate = $_POST["cate"];
* X9 u& i+ ?! a- B, m% ^ - //print_r $tags;
) b F6 d5 k, q& ?! k - //
$ E0 a7 p6 ?% I* K6 D- z - //
) U% x4 D! G# U6 R# F( V - $wp = new WP();
6 g/ i4 ^! ? }3 R4 ^/ }. I2 {8 ? - $wp->main();
; l- f0 F7 J9 ?6 ?- ^ - //% Y4 |- k1 k& l4 q3 X2 y+ ]
- $my_post = array();8 [1 Y+ M# T2 g q9 H5 g
- $my_post['post_title'] = $title;1 B6 A/ v9 {9 n& D& B/ J( n
- $my_post['post_content'] = $content;
, g& G1 X0 `& I6 v - $my_post['post_status'] = 'publish';
7 B8 ~$ A3 W+ l- e" i - $my_post['post_author'] = 1;; M5 T O( Q$ ^+ N$ k6 r
- $my_post['post_category'] = array($cate);
' y" @$ ]" E4 S6 f% l - $my_post['tags_input'] = $tags;; D8 S, _% y2 T- P" O- f$ Q
- //$my_post['tags_input'] = array('tag1', 'tag2');9 P% L. H6 @2 x! J; c3 a
- //$my_post['post_status'] = 'future';% Q% i7 M. f, e, X* g
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
5 v# ~# p: B( A( B; a5 V - 4 @/ x* p4 i7 }7 D' c/ {# Y
- // Insert the post into the database2 e& l$ _% l5 H
- $ret = wp_insert_post( $my_post );% \* j+ _5 X* ~$ X; D! a) T7 s" F6 S, g
- echo $ret;4 c6 O) g' A9 _5 K* |- V
- ?> V \8 }7 G4 ?* w9 r
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 7 a6 d- L% V. h- d5 k& G
- <?php* d/ t6 {' b- b: I7 }
- define( 'ABSPATH', dirname(__FILE__) . '/' );
g8 w7 Y v: P( h2 b# I& N - require_once( ABSPATH . 'wp-config.php' );
5 I" c& N8 a5 D& A+ \% T - require_once( ABSPATH . 'wp-settings.php' );
! n" G1 n1 c$ f! t# C ?' W - require_once( ABSPATH . 'wp-includes/class-wp.php' );
% F* _6 n4 j- h7 B& {# l - require_once( ABSPATH . 'wp-includes/functions.php' );
1 m1 T7 w+ R9 a, N5 \4 P - require_once( ABSPATH . 'wp-includes/plugin.php' );& E1 X( S1 m2 S6 [! N
- $pic_name = $_POST["pic_name"];
6 S8 G( W" o5 h, @( o - $pic = $_POST["pic"];
! V, L* n2 _7 j( Y* l$ N+ _! A: e1 \ - if($pic != "" && $pic_name != "")7 K$ z r3 `, a& a6 l7 o
- {
, |& c$ j& [4 k4 @* N - $path = "images/";/ Q3 ?; y8 k6 {( n8 V/ @
- $pic_name = $path.$pic_name;, u3 ~/ S' F( R: {( T0 r
- echo $pic_name;) F% J3 T* J" ~1 o& ?
- echo "||";( X3 {( E& ~/ v% h; n7 ]
- error_reporting(0);+ v2 l$ `' G; S% J6 v0 l/ x4 ^& [
- mkdir("images");4 [& x+ N' ^( R
- $handle = fopen($pic_name, 'w');
1 V, T$ _( ?, K) S2 W - echo fwrite($handle,file_get_contents($pic));: s* c9 A7 ]" J
- }" j+ X) I# \ h4 k7 H/ i0 Q* }
4 V$ N4 H) _5 s& K: Z, y1 I) w- $title = $_POST["title"];. ?: X* [8 d" P% F/ \! Q- X. l( m
- $content = $_POST["content"];
* n# B0 E1 B) X, v. C - $tags = explode("_",$_POST["tags"]);9 _3 E+ E: N& D4 a6 W; q
- $cate = $_POST["cate"];
$ J' B! H& b* S - //print_r $tags;9 a& S0 {8 {4 `
- //" W: A7 I; s$ o5 {
- //( U1 @$ X' U* e6 @' l
- $wp = new WP();
" W) [9 ]( r; u - $wp->main();, A0 M/ [+ p0 \2 Q4 |
- //) j; q$ F3 e9 j* Z9 e, m. i. s
- $my_post = array();
% _& V* b9 j6 ?1 P V/ V - $my_post['post_title'] = $title;' B Y# l+ z, ~7 B$ \2 \$ ^3 `: C
- $my_post['post_content'] = $content;$ g; c2 z X3 U. E& e' m0 G
- $my_post['post_status'] = 'publish';
3 H; |$ G0 y: K7 ], q7 D& | - $my_post['post_author'] = 1;* Z$ N; Y3 c8 L: W7 o0 Z+ v
- $my_post['post_category'] = array($cate);+ I0 T" n4 `! n) y% m* Q
- $my_post['tags_input'] = $tags;
' j, j1 o. \; G) a1 p% s& w6 S - //$my_post['tags_input'] = array('tag1', 'tag2');
0 Y f( {$ o' ^ - //$my_post['post_status'] = 'future';1 u; a9 _6 U) J. I) R0 H' [/ p$ u
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
/ b: j S3 k, S- x - * |8 O/ p# M8 L# ?4 n
- // Insert the post into the database
$ \9 {6 _5 y) w1 ?$ K2 J - $ret = wp_insert_post( $my_post );
9 V# ^5 w+ j$ p) b - echo $ret;/ E4 G. c5 u3 Y5 ^8 a1 Y# a, _
- ?>
- |8 z' N1 p$ q l$ @
复制代码 我自己写的
+ U9 ?1 D) w8 H! `! ]插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|