|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
, j7 g2 G: `" G$ f
3 G+ y1 b. u8 S5 j直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
3 } s0 N( @$ n( _& L E! L0 z0 d3 f# u2 @; ]. F
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
+ l- N/ f" c) G' a
9 _- @2 ~ D0 f! S5 o方便实用 简单 何乐而不用呢- / ?& R4 ]! d: [9 a, R
- <?php
6 `. u3 m8 s- y5 D' t9 D - # I" X' a) y$ K$ l [1 J
- define( 'ABSPATH', dirname(__FILE__) . '/' );
6 D" @, ^5 H2 r% n - require_once( ABSPATH . 'wp-config.php' );6 @+ _, J3 L/ D t2 u
- require_once( ABSPATH . 'wp-settings.php' );
7 q' R. J; s0 v& @) ]6 i- O ^3 W - require_once( ABSPATH . 'wp-includes/class-wp.php' );* q9 d1 [1 R* a8 I
- require_once( ABSPATH . 'wp-includes/functions.php' );
& k2 u8 x5 `; J0 Z, ^- l0 A& R5 L& b - require_once( ABSPATH . 'wp-includes/plugin.php' ); c! m: }3 L% s0 L* ~' C
- $title = $_POST["title"];
+ q F5 L% J- y) ?" h - $content = $_POST["content"];
. A. r8 S4 S6 ?7 I7 F# t - $tags = explode("_",$_POST["tags"]);5 Z! `( t8 i; W5 Z2 T* E8 r1 ^
- $cate = $_POST["cate"];
; |8 i& S" _ S) ?$ b+ W - //print_r $tags;
1 z# D, j8 j' @" J0 L. p$ _ - //* i5 x1 T7 A" ~( K7 x
- //2 t+ P8 L, h1 \5 u) I& M
- $wp = new WP();
% Y% \/ l' m& ^ - $wp->main();0 s& S3 M6 r7 ~ L7 f% U
- //
' R# a6 ?; n1 `' k, L - $my_post = array();) `: i+ \, d3 }- g! G% m( t
- $my_post['post_title'] = $title;$ Q+ B% [0 J6 [! [: v+ x/ [
- $my_post['post_content'] = $content;
7 i0 ], Y' K1 v( r; ?2 n7 a - $my_post['post_status'] = 'publish';0 |& Z, m. O9 N% m: l* o
- $my_post['post_author'] = 1;
) s4 r- W3 R# E. q - $my_post['post_category'] = array($cate);
) K" i* `$ e9 e% `$ r - $my_post['tags_input'] = $tags;2 J& f* ^; Q4 t: o( R! _- n9 e& c! m
- //$my_post['tags_input'] = array('tag1', 'tag2');
" Q3 N8 w* _& ]: c+ r - //$my_post['post_status'] = 'future';4 s4 R$ L7 a: ~/ w6 e
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
- E4 f% u a1 d* P& M9 H - : b y, m, u2 Z/ k1 b* Z; W
- // Insert the post into the database) @9 L1 u# u+ O# M' e _7 h
- $ret = wp_insert_post( $my_post );
" t& @" Q) h7 _6 N9 \% m; Y - echo $ret;, ^& O/ v; e7 \" u6 ?
- ?>
3 L1 }4 x) u- {( @+ D- }4 u# ]; \. L
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- # r0 @2 w* u/ S" a0 I
- <?php d% W6 G5 V) k. t( a+ ?
- define( 'ABSPATH', dirname(__FILE__) . '/' );
+ [0 B9 T3 q8 X& S - require_once( ABSPATH . 'wp-config.php' );" F: T. w1 g0 @# y4 t! a& {8 k
- require_once( ABSPATH . 'wp-settings.php' );8 p, u% w0 X# @9 m( w3 U2 X0 ^
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
8 c @* ^' H% `% y5 x6 e - require_once( ABSPATH . 'wp-includes/functions.php' );
0 A) U1 A" ^$ Z1 Y5 d. u - require_once( ABSPATH . 'wp-includes/plugin.php' );1 C# h0 a8 k0 w$ N% D5 W
- $pic_name = $_POST["pic_name"];
2 s Q& R, K7 L; M1 |, n - $pic = $_POST["pic"];
$ @2 a' q) R9 w; C - if($pic != "" && $pic_name != "")& P2 h# ?1 h9 o6 k( ]
- {) h- }3 A) f: B! e8 ` Y
- $path = "images/";
/ c' }. H ?1 g$ [" R! u - $pic_name = $path.$pic_name;
8 n0 @, |- w! L" t9 u: ^+ ] - echo $pic_name;! \' p, X/ U/ `7 C5 v
- echo "||";0 ^4 s' V/ e0 O2 \2 ~1 i
- error_reporting(0);; W, N8 I/ Z! ~ E: _
- mkdir("images");1 |7 H" h S- ^) K
- $handle = fopen($pic_name, 'w');
; ]! d8 o& d% ` p* k1 J( N1 t1 m1 m - echo fwrite($handle,file_get_contents($pic));
6 Q) J( u7 N2 Q' }6 W - }
( I( J& K, M. w; }& C0 U5 |
& j% V! ?5 ]& A# r- $title = $_POST["title"];5 c& @0 v/ F4 C; \7 a9 i
- $content = $_POST["content"];) S: Y; c5 ^' ~+ V3 f
- $tags = explode("_",$_POST["tags"]);
5 B, g5 v5 E, s5 T - $cate = $_POST["cate"];
. q: X3 H5 S! a3 b ^9 \5 x+ ~ - //print_r $tags;3 S5 x s' L. H# z) J6 L
- //
: V; `/ `. J; n- G9 d0 `+ U - //5 ]" m% {* l _: r# q
- $wp = new WP();
; ?' W+ o- p1 O6 N, z( U0 J7 P - $wp->main();0 W5 [' p, b f. }1 E
- //; P# v6 r) s% Q& g2 L1 }
- $my_post = array();
' y* u) k% E0 G4 z9 Y - $my_post['post_title'] = $title;
+ Y7 w4 v& C4 @: [. E - $my_post['post_content'] = $content;4 q' X. j% Q6 |( F
- $my_post['post_status'] = 'publish';' }6 D5 a$ P" X' p/ w4 I2 H
- $my_post['post_author'] = 1;; ~8 r' E7 z& x6 f& r
- $my_post['post_category'] = array($cate);7 B* }& U- b1 B
- $my_post['tags_input'] = $tags;
3 b- ~* g- d# @9 w - //$my_post['tags_input'] = array('tag1', 'tag2');/ A9 h" m5 D# |
- //$my_post['post_status'] = 'future';
9 A; ~/ a" ]% l R* U6 n - ////$my_post['post_date'] = '2010-07-04 16:20:03';, a1 Y& V: v/ c- l
K6 G# W+ i% v- // Insert the post into the database
9 n/ M" e. Q9 g4 N - $ret = wp_insert_post( $my_post );3 {2 N, z* w$ u
- echo $ret;: ?5 D$ }6 ]' W7 f1 _
- ?>
, P4 }, T. ?3 ^& i# ^
复制代码 我自己写的3 {! P0 `; O" i# S7 B$ C
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|