|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 : O& K1 U( w4 M% ^) y
* s" V$ ]; J% S
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
" N% j+ V8 i- J: u# o- @0 W3 @
+ d5 R6 Q( V0 R- v9 P0 p9 {我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了+ k% K7 `- t6 X0 K2 g
; I* ^- C* \9 d+ j
方便实用 简单 何乐而不用呢
+ X$ Q% S. D0 T: n4 r( | D" ~" i- <?php" k/ e8 Z1 Z' ~/ p2 x
- 3 U& {0 k6 J/ m# F
- define( 'ABSPATH', dirname(__FILE__) . '/' );
& p, q/ p* x* H( t: D - require_once( ABSPATH . 'wp-config.php' );
; e) C* K- C4 H! j - require_once( ABSPATH . 'wp-settings.php' );' M! b ^& W; [+ W0 B( r' u% m
- require_once( ABSPATH . 'wp-includes/class-wp.php' );9 q) C8 S. @6 g: f/ P& }5 S
- require_once( ABSPATH . 'wp-includes/functions.php' );
. y8 h! L( }7 r$ `; \3 _ - require_once( ABSPATH . 'wp-includes/plugin.php' );1 W" w$ ]4 x4 N' N
- $title = $_POST["title"];6 V6 w1 C9 B2 ]+ Z# T' J* r
- $content = $_POST["content"];
" |9 ~. U) B0 u, h5 [ - $tags = explode("_",$_POST["tags"]);
5 s3 d4 W8 K; \8 l - $cate = $_POST["cate"];
; ^# O1 B1 k* W - //print_r $tags;
' e0 q; r4 ^) [, H9 J& a - //' W. Y( H4 ]. J7 x" e b$ U
- //
: s* m3 G5 A; l - $wp = new WP();( }3 R2 u( m2 X- }- k
- $wp->main();2 N# }% |7 W+ y4 Z
- //6 L/ ^8 [+ m8 R' M6 y8 b1 Y
- $my_post = array();; `" {" s* U. o; }
- $my_post['post_title'] = $title;5 _8 n4 p) Y0 H' z: z5 T
- $my_post['post_content'] = $content;6 b- j% T1 [, s0 K" ^) {) o/ |$ S* S
- $my_post['post_status'] = 'publish';
# i& r8 Z9 F' L# [; E - $my_post['post_author'] = 1;. n2 T) N6 p0 Z
- $my_post['post_category'] = array($cate);' g/ d: Y3 z# ]4 G, G1 J9 Z
- $my_post['tags_input'] = $tags;
. _0 p! V$ f' X( h+ @9 H7 h9 X, I - //$my_post['tags_input'] = array('tag1', 'tag2');
2 [0 I' M" f/ r2 D) U/ }, A# { - //$my_post['post_status'] = 'future';7 | \1 n1 G1 s# j4 v W
- ////$my_post['post_date'] = '2010-07-04 16:20:03';& ]4 }( L" r) ^: V8 L
- 9 R; |* {: `: T/ x
- // Insert the post into the database
+ @. t1 _, T! A; K - $ret = wp_insert_post( $my_post );1 a, D$ H- I+ f) [$ G" U
- echo $ret;' N8 @- X% ]/ Q
- ?>
5 U3 I8 E: S. r- ~" t
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ) ?; ?8 S: Q& ]8 L" R
- <?php
- ~! w/ O: K1 R- p - define( 'ABSPATH', dirname(__FILE__) . '/' );
1 W1 B2 I5 r' Y. D. u9 I" ]0 p - require_once( ABSPATH . 'wp-config.php' );: M. ]: U6 D! p
- require_once( ABSPATH . 'wp-settings.php' );
& T: [ b+ V4 I+ t - require_once( ABSPATH . 'wp-includes/class-wp.php' );
4 [0 J# l& |& Y1 J - require_once( ABSPATH . 'wp-includes/functions.php' );) P0 G" x9 ^- s& k
- require_once( ABSPATH . 'wp-includes/plugin.php' );/ s6 Q* F3 |+ l( M
- $pic_name = $_POST["pic_name"];1 a( A" l4 m$ ?7 }& J6 H; ^
- $pic = $_POST["pic"];0 R0 e/ V' y: _0 _3 S4 S
- if($pic != "" && $pic_name != "")
6 s) g" b3 J( k$ L - {
/ h7 I* V- J" \% r - $path = "images/";
G, V" m; t+ R1 i' p - $pic_name = $path.$pic_name;
' z5 h! R7 U2 X2 u# n; W q( }& @ - echo $pic_name;
6 g I& p% N# ^7 u - echo "||";8 n0 q# o& V- J# s' _
- error_reporting(0);
2 p* X. o5 W+ Q/ N1 a6 l) V+ I - mkdir("images");
& _7 v; }& f$ D - $handle = fopen($pic_name, 'w');$ ^2 ~# `1 i* C& y4 E" Q- n
- echo fwrite($handle,file_get_contents($pic));
; M. h. c) c7 k3 i: P8 a - }
; |6 t5 z" b# u$ G j - # c7 W( P. w$ q# u; A( X
- $title = $_POST["title"];
* P( z" o F$ b7 C) h - $content = $_POST["content"];/ N* }1 |# G7 ?% L7 h
- $tags = explode("_",$_POST["tags"]);
- ~! U. M# j7 _+ O' a - $cate = $_POST["cate"];3 T1 w- M9 `- A, C, W
- //print_r $tags;# V' c6 }7 M( z, H& A: C' c* b; [6 L
- //
, c0 f" w7 t* Z, O: B - //& d( t |" U E1 J( Q+ K
- $wp = new WP();/ `4 ^9 |8 q$ ^2 P9 Q+ r" Y
- $wp->main();
2 d% }% `8 _4 w! ? - //
, S& k4 W" ^1 k4 Q: J, D - $my_post = array();4 u: |2 P% \6 w! K+ l- q% k
- $my_post['post_title'] = $title;
# B+ k+ y0 t! L# D4 z. X# ~7 ~ - $my_post['post_content'] = $content;
, X8 x& w0 J8 @& M ~ - $my_post['post_status'] = 'publish';
R6 u" r& g3 N& z1 F9 y# e - $my_post['post_author'] = 1;
; `1 f" P+ D# [. _/ O6 d: t4 h - $my_post['post_category'] = array($cate);( f: ]6 W+ |# }/ H) x
- $my_post['tags_input'] = $tags;
* l0 B1 K: \7 L; C2 ` - //$my_post['tags_input'] = array('tag1', 'tag2');
; B- \4 V* t1 L0 V, o( a - //$my_post['post_status'] = 'future';
& [- b4 K+ `8 q, s' e3 O - ////$my_post['post_date'] = '2010-07-04 16:20:03';3 S, R n( y$ J' K2 A4 o
- . R" P, R% e/ L$ P3 |
- // Insert the post into the database( u- m- {, I- B) L+ Y
- $ret = wp_insert_post( $my_post );
( R/ C) N! f# ^2 f4 f" s. P, K - echo $ret;
$ V9 d/ M6 r9 k& l3 B0 I* I3 c - ?>* }0 J! }- A; b6 `1 g
复制代码 我自己写的0 @3 C) @# c! F( Y/ ` u. z
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|