|
本帖最后由 finder 于 2014-12-28 15:13 编辑 6 P N5 J$ ]+ t- K5 T
/ j0 c' d3 U9 Q, x% Z# T
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
{1 C5 J5 G, R1 w8 ?/ } H5 U& ^) Y2 l0 C; K J1 r- r
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
( O* `5 x- O, h8 F U# q: n8 z! |3 I8 D) [3 A" T; s% C7 ^( I
方便实用 简单 何乐而不用呢
% U" ?" t' b: g. U2 T) J- <?php N- y3 ^3 r" u7 r: o* @/ H
- + g, ^$ a: `* ~: \5 x* N- F
- define( 'ABSPATH', dirname(__FILE__) . '/' );* t4 N2 D0 }- A, R5 O% d# O4 @/ E9 i
- require_once( ABSPATH . 'wp-config.php' );
% d. z$ U- E) ? - require_once( ABSPATH . 'wp-settings.php' );
% M/ {9 |3 e2 x) V - require_once( ABSPATH . 'wp-includes/class-wp.php' );
; z! _0 O# ?6 a! u/ g( P& ^: n - require_once( ABSPATH . 'wp-includes/functions.php' );; _) j7 E) X) w4 E# p; D; M
- require_once( ABSPATH . 'wp-includes/plugin.php' );
; j& [% P( p/ T! m - $title = $_POST["title"];2 v/ Z' ~" `( ~ f1 [
- $content = $_POST["content"];
+ {$ O6 x2 n1 r' n - $tags = explode("_",$_POST["tags"]);
5 a8 A7 l5 G r( r: @: W( | V3 H - $cate = $_POST["cate"];
' r' T4 A$ V8 n1 V - //print_r $tags;/ h9 I; v; r- l) v. o( U+ @. B
- //0 t; r8 h `8 d
- //: ?# \" M, X1 Z4 i! J/ ~" a
- $wp = new WP();
* V$ d9 m, v% h, J$ e - $wp->main();
. _+ s- F5 j: d& {7 N' V - //
; {6 ~% [2 k4 r" D5 l - $my_post = array();
6 S8 q# w6 O- v$ r! a - $my_post['post_title'] = $title;
5 ?5 I6 r' s9 g; R3 \5 [; s/ L - $my_post['post_content'] = $content;. o6 f& H$ l7 r6 \
- $my_post['post_status'] = 'publish';" y! p: r. g7 Q& E
- $my_post['post_author'] = 1;0 Z3 y, j3 x4 e* n
- $my_post['post_category'] = array($cate);+ y/ Y. ` |3 x8 C, G, H3 T
- $my_post['tags_input'] = $tags;
/ I3 _; ?/ a0 |. S0 ]0 G5 c7 R - //$my_post['tags_input'] = array('tag1', 'tag2');
# z1 i* W9 a; ]0 \ - //$my_post['post_status'] = 'future';
. \% g) U) i/ z. H* n+ F - ////$my_post['post_date'] = '2010-07-04 16:20:03';% `6 m* e6 K* n( q/ X! `
- 8 Z: w9 ]7 y4 w/ G" U7 f
- // Insert the post into the database" X; C9 I# X3 h; t
- $ret = wp_insert_post( $my_post );7 p; k8 T3 `( R* l
- echo $ret;7 r! r. i, R- \& v3 Z1 p% [
- ?>+ D U4 o1 [& r( m; m
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
* X: o, O t2 ]. K" b' I- <?php: n1 F7 D6 d) f) l+ l1 m/ A
- define( 'ABSPATH', dirname(__FILE__) . '/' );. k& {8 J# [, [. [: H5 g' q6 E
- require_once( ABSPATH . 'wp-config.php' );( h6 L3 W9 E7 X) z# T
- require_once( ABSPATH . 'wp-settings.php' );6 Y t) C8 S8 ^
- require_once( ABSPATH . 'wp-includes/class-wp.php' );% z! z! N- |- V L/ \/ o2 ~- R$ E
- require_once( ABSPATH . 'wp-includes/functions.php' );
9 ]8 ]5 `" Y5 h9 i - require_once( ABSPATH . 'wp-includes/plugin.php' );0 q+ m: ?9 f) ]7 m- d% F _% N c
- $pic_name = $_POST["pic_name"];
) y1 _ N o% b. o0 T M - $pic = $_POST["pic"];, I5 x6 P, m5 F% a$ g& V: }
- if($pic != "" && $pic_name != "")
5 w+ H; g9 G' t& Z4 \ - {1 I; l$ C/ ]8 s- I
- $path = "images/";) u4 a5 f: L8 \: ^
- $pic_name = $path.$pic_name;
/ F* q0 [% t: r+ o2 f; t3 _. J - echo $pic_name;, e& [& f- h9 l4 ]) \+ h) K4 X; Q
- echo "||";
: o2 F5 @1 g# z! V8 m6 j - error_reporting(0);0 D3 v1 C0 i% s6 Q
- mkdir("images");
2 R" ?9 l% D' P; p! S4 F7 { - $handle = fopen($pic_name, 'w');! n) L; b' X; v) _2 Z
- echo fwrite($handle,file_get_contents($pic));2 k3 W9 M ~0 H3 f" e: o$ U2 P8 I B
- }, A8 j( u' `9 L3 L3 j& {
- 1 z( V/ m; Y! W0 s. |
- $title = $_POST["title"];, F- n) y! M1 @$ ~/ y& b
- $content = $_POST["content"];+ X# y4 }% n7 h' i7 `% [5 P9 s
- $tags = explode("_",$_POST["tags"]);
" S5 _7 D; N i# Q3 {, q - $cate = $_POST["cate"];( n" R" W% j( H& j K, t
- //print_r $tags;
2 o' W. i. `' m) s/ H. [ - //
5 [; Z) c" G9 a4 u: R - //4 [5 M9 V. }" F* a5 j9 j8 @
- $wp = new WP();+ N* X' \( Y* r9 ?+ N4 g& B$ u7 t
- $wp->main();
/ H a) a$ T3 K. ]. r/ ` - //
4 J' p; h( r2 C4 E, k" W - $my_post = array();
; b5 \& o4 D# W - $my_post['post_title'] = $title;
. A6 M" x2 m, Q# Y - $my_post['post_content'] = $content;
6 O$ v: [* f: n( J - $my_post['post_status'] = 'publish';
8 W/ C* K: J% f - $my_post['post_author'] = 1;& t$ ~+ g" n K! n3 Z
- $my_post['post_category'] = array($cate);
0 a( W1 V5 C& S3 Q - $my_post['tags_input'] = $tags;. [7 ]3 R3 X9 D' B( \
- //$my_post['tags_input'] = array('tag1', 'tag2');. B7 x+ |; t$ Q" w7 N2 n
- //$my_post['post_status'] = 'future';* u7 @, I8 w3 Q
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
% c+ |! l" q5 r" Z8 w- l8 d) T: |
3 P' q( ^) C4 e2 i' q- // Insert the post into the database. a# k# ]8 a" q' e; S0 y
- $ret = wp_insert_post( $my_post );
' I! @) o( L! z6 ~8 D( i - echo $ret;4 w3 R& Y! s# l6 j3 I
- ?>
3 X2 N8 [& E2 b$ O R6 n
复制代码 我自己写的
0 E* N+ y" F2 w/ T& [ m插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|