本帖最后由 finder 于 2014-12-28 15:13 编辑
6 F# F+ X* D5 {3 L2 S0 K9 P, R* E- ~5 H- }: H: ~
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
X2 e$ m/ f* W: h; }" r6 ^6 r7 R! y8 E/ Z9 A7 v, t
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了$ H6 B( M" U+ X* b. U: u
* Z8 C. q, N5 o S/ ~/ S% T方便实用 简单 何乐而不用呢- " q- @3 H; z* `- d% M, y
- <?php
; u! _9 f2 }, y% H Y6 Q
j7 y% c4 |$ U9 H9 d, j g4 g- define( 'ABSPATH', dirname(__FILE__) . '/' );
! h. u2 {8 I4 @! l4 | - require_once( ABSPATH . 'wp-config.php' );
* b; i$ H J$ i- v5 r - require_once( ABSPATH . 'wp-settings.php' );6 n: ]) T* F4 |
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
0 b+ p2 i9 R7 b1 t - require_once( ABSPATH . 'wp-includes/functions.php' );( p& T2 }, @) p8 T' A
- require_once( ABSPATH . 'wp-includes/plugin.php' );
$ }% U. O+ Q9 ] - $title = $_POST["title"];
! @3 d, I2 a7 e' }' \* u7 m4 T7 }5 ` - $content = $_POST["content"];2 V5 Y2 R I* F/ z
- $tags = explode("_",$_POST["tags"]);8 B# B- G) ^8 f, W" t
- $cate = $_POST["cate"];
) L( L/ ?: l& @' n4 H - //print_r $tags;! M% {1 `8 u+ R: I. n# Z; ]
- //9 D" m. s1 q. R9 y. R
- //
" i( r7 P# {. a3 j: I- Q - $wp = new WP();. @; n. N* K0 E. U
- $wp->main();4 b; H) A7 }' P! |
- //
/ f+ d, K. f" q: p - $my_post = array();
4 ]0 L1 n8 J* K2 B; B - $my_post['post_title'] = $title;
/ x% ]/ r: \/ `* p T - $my_post['post_content'] = $content;
3 {" J: R5 O; X* ?. T0 T4 k - $my_post['post_status'] = 'publish';2 h) r! C3 \9 x( K& w0 W
- $my_post['post_author'] = 1;/ o# n! Y3 o+ z# [. C C
- $my_post['post_category'] = array($cate);
/ b8 k* l/ t* V; c; b - $my_post['tags_input'] = $tags;
+ Z, w, a/ V: }$ b+ L - //$my_post['tags_input'] = array('tag1', 'tag2');) K/ J1 M7 j" J; A
- //$my_post['post_status'] = 'future';* U& R+ j" h- c; U, F, ?0 ~0 J7 d( n
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
8 |8 c! Y# T7 D& i* O p: k7 H - ! L4 Y; n9 t5 p6 Q
- // Insert the post into the database
/ H4 U, f: o, o+ }& T - $ret = wp_insert_post( $my_post );
- `& y3 ]- W8 R, J/ ?/ P - echo $ret;
2 B- V: y% l& n P1 m - ?>5 l1 C8 l0 E4 s
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
/ y- `: z7 h$ S; t% B& V# G p- <?php
) H) b5 _& g! u( G$ x# q - define( 'ABSPATH', dirname(__FILE__) . '/' );
/ O% D% u8 K, f: ]; u: T8 q - require_once( ABSPATH . 'wp-config.php' );, d5 r3 q4 _! X9 H5 m
- require_once( ABSPATH . 'wp-settings.php' ); L) D' ^2 b) U0 `) Y
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
5 E# m$ T& p% s - require_once( ABSPATH . 'wp-includes/functions.php' );
& P8 v, T) M9 w, `- E - require_once( ABSPATH . 'wp-includes/plugin.php' );' ?, ], u! L! M) W. M" C1 s; @! ^
- $pic_name = $_POST["pic_name"];+ Q: k6 W, w" ^" K% X
- $pic = $_POST["pic"];
$ G3 I& [' A3 s9 g - if($pic != "" && $pic_name != "")3 N- B6 y# `7 E, p# z$ X
- {( P! D+ v M7 |, F% J
- $path = "images/";
1 o5 o+ C, r, j - $pic_name = $path.$pic_name;
: a' H- Z, V, }) V3 L: c - echo $pic_name;
2 N: f) g) R" k! y' d' N - echo "||";
y, p5 c8 W2 a4 G$ c- ^8 ^ - error_reporting(0);" t1 j' M r, {
- mkdir("images");
) d6 ~' ]2 k+ W& Z, V; G( W - $handle = fopen($pic_name, 'w');' j3 f" S1 k8 E! Z' Z0 }2 b% f
- echo fwrite($handle,file_get_contents($pic));% Q- F/ [' Y1 E5 `- h4 E
- }% [/ n" z$ ]3 n/ y' P7 W. U
- 3 e) K6 Z1 U. M! s
- $title = $_POST["title"];
& Q6 g% b5 Y' H# G* |+ ~1 M4 g# ? - $content = $_POST["content"];9 F8 [5 v2 c+ T& [: U0 T: m
- $tags = explode("_",$_POST["tags"]);
& [' h; ~% N- t - $cate = $_POST["cate"];
7 M6 i, F" K }8 H% d- e - //print_r $tags;/ Z* |; r) q3 G5 {' Q- a4 d
- /// c; Y! c- Q* P
- //, X1 J) {1 I4 `& i4 H2 M! M7 r
- $wp = new WP();
2 i1 v: k% n a. Q - $wp->main();- a1 M; N6 x! l) C1 }, d4 G* _, B j
- //3 [) ~7 x% o1 ]# U" e1 c* e
- $my_post = array();
; M7 o, R% w4 h; @ - $my_post['post_title'] = $title;) P1 W9 H' J' _( x+ @9 `/ \: n
- $my_post['post_content'] = $content;
3 ]1 q" G; D' O9 h2 m2 q$ p - $my_post['post_status'] = 'publish';
* Z- Z' ] z' @, T. a$ x; y - $my_post['post_author'] = 1;& \ G9 L- t [# B) G& X8 d/ B
- $my_post['post_category'] = array($cate);
# {. ? B/ T+ z3 s# q! ~ - $my_post['tags_input'] = $tags;
1 A6 B0 j3 _4 F( o @- G - //$my_post['tags_input'] = array('tag1', 'tag2');
$ F& s- M# Q7 ^ - //$my_post['post_status'] = 'future';
# |, i; l9 R. O - ////$my_post['post_date'] = '2010-07-04 16:20:03';/ l8 n0 |6 N9 E# ?
- 5 D7 k* \" g9 W7 u
- // Insert the post into the database
/ A+ W8 v! b1 \5 a( s) K) d( o4 ^ - $ret = wp_insert_post( $my_post );# b, b8 Q$ H6 N# Z0 Y* s h; r. I( U
- echo $ret;' v5 H. I' B# N+ E8 T7 ?& ?: o
- ?>1 g- U* ~( e% S# C4 q4 M
复制代码 我自己写的
7 M8 l9 U' B0 Y/ }7 @/ M3 y: A插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |