|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
5 E- ]/ G6 {) X l* C0 t
, b Q2 K" A$ P: }' o) h% d直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持* G$ V. p9 n7 E5 t7 J- V
6 r" }, R5 R% p; M2 @% }9 U我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了6 k: C& {! N5 E1 j8 E
5 b c0 y" H, n; P R方便实用 简单 何乐而不用呢
4 B9 \" ?4 y0 I1 @$ Q9 i- <?php
$ M/ t7 M. {8 {9 V2 k - & V; c' n3 P/ ~" L- f. }
- define( 'ABSPATH', dirname(__FILE__) . '/' );- _# U: Z- ~* s* U" I4 }
- require_once( ABSPATH . 'wp-config.php' );9 @7 D/ ~! V+ Q' ?- l0 I5 f( U
- require_once( ABSPATH . 'wp-settings.php' );0 \5 ^, a/ B* [) k w
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
$ b) q9 i5 ~$ m# V - require_once( ABSPATH . 'wp-includes/functions.php' );
/ W0 g! a0 f$ y: G - require_once( ABSPATH . 'wp-includes/plugin.php' );7 V: f' x2 t8 L/ r) T
- $title = $_POST["title"];$ a4 R9 K, q* q/ [
- $content = $_POST["content"];
1 V7 b" K" _5 g2 S+ E - $tags = explode("_",$_POST["tags"]);
( ~2 w0 a7 P* }) C - $cate = $_POST["cate"];
3 L p" ~& D$ C: M - //print_r $tags;
2 ^7 n* ?* w' D' v - // n+ b3 e! P! ^0 {" {9 p
- //* N% w5 o, x6 X$ K8 E3 u
- $wp = new WP();
2 `5 I; l( Y5 \( _9 R2 l: v - $wp->main();" t4 e5 L& {1 A- D3 C; z
- //( R& l* ^9 x2 J& E$ {. q
- $my_post = array();
: _" b0 N- r- z# y* L4 z/ C - $my_post['post_title'] = $title;
- @7 H7 N0 K4 o - $my_post['post_content'] = $content;$ j1 b6 |# y. F, S' \, H
- $my_post['post_status'] = 'publish';9 t. [. b, E$ A6 h b
- $my_post['post_author'] = 1;
# Z% t$ _3 z7 |0 r ^, s4 L1 s - $my_post['post_category'] = array($cate);
. ]. N3 u# T* C0 M1 J - $my_post['tags_input'] = $tags;
) A" W7 k' ^3 h - //$my_post['tags_input'] = array('tag1', 'tag2');2 O9 X3 B) |: H5 q7 @, S
- //$my_post['post_status'] = 'future';
! P1 e) a" E$ S @7 E9 o - ////$my_post['post_date'] = '2010-07-04 16:20:03';
& T0 J* H8 s) n! j; _' U - 1 u, ^, \ Z" N) s
- // Insert the post into the database
# E* _! o9 S0 V - $ret = wp_insert_post( $my_post );( J2 D$ V" O, U9 C! c
- echo $ret;
1 Y! @& n# h9 B - ?>
& H$ X+ ~1 N7 ~
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 1 N1 j- }" _0 X$ b
- <?php
; L6 ^2 s e2 f7 o* _6 v - define( 'ABSPATH', dirname(__FILE__) . '/' );2 N) F A. @) W. f! L! s
- require_once( ABSPATH . 'wp-config.php' );
: ~8 E8 W4 e4 }+ O+ k2 L8 F - require_once( ABSPATH . 'wp-settings.php' );( i; l( X) [! ]2 P
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
9 y3 T1 m& F1 z0 ] L/ H* k- _ - require_once( ABSPATH . 'wp-includes/functions.php' );7 m! s; ^& v h1 M1 y( ^
- require_once( ABSPATH . 'wp-includes/plugin.php' );
: N3 i/ P5 G! p& M% U7 O6 b @7 Z9 _ - $pic_name = $_POST["pic_name"];
' A! L% _$ J5 l+ @/ \5 V - $pic = $_POST["pic"];
6 f' v& e* x& @' N - if($pic != "" && $pic_name != "")
) V; |+ A* L% K9 R6 T( t - {
, F! o+ j: i. ]5 x! L# D+ ]9 {; j8 K - $path = "images/";$ o, K3 h1 p; g* u( D2 o$ _5 |' y
- $pic_name = $path.$pic_name;
) b5 r( F5 W/ N' I" T3 a! u - echo $pic_name;
/ o3 x+ L: \, G% {2 Z2 T - echo "||";
/ i/ K: P! u, \, Y- s8 p8 y - error_reporting(0);) n- P$ _! W! e7 i
- mkdir("images");9 Z2 G, M% T, \$ d% l
- $handle = fopen($pic_name, 'w');
5 U; ^5 |6 C8 ]# b4 @ - echo fwrite($handle,file_get_contents($pic));
3 G+ ^, ?3 c$ P( D& ]; y8 x$ h - }
( a4 m* {' M) y1 G4 x - 9 S; S# c/ Z( P X+ l) _! y
- $title = $_POST["title"];! w# T5 a# q9 A" Z
- $content = $_POST["content"];
' `8 M) ^3 V$ |. {; Z$ ~+ H2 [9 i - $tags = explode("_",$_POST["tags"]);
4 y$ Y9 f; d& s7 [ - $cate = $_POST["cate"];1 F3 i6 a2 H. J. H& H2 P
- //print_r $tags;
6 c+ q, Y3 r; a - //: Y" E, s9 y4 P
- //$ k+ l# e, p. c
- $wp = new WP();8 p1 Q7 c2 u; V5 }1 |9 N. }. m
- $wp->main();% t# O& x2 J% J
- //& b* z& p1 U' Z" r$ r9 v( w3 Y
- $my_post = array();+ Q8 ]/ G; l8 M
- $my_post['post_title'] = $title; i5 y8 e0 d/ J( X, C
- $my_post['post_content'] = $content;+ u! @! J2 A, K. c+ \% T |+ n
- $my_post['post_status'] = 'publish'; P/ h$ a" v$ u9 n( z( a
- $my_post['post_author'] = 1;
/ v) D) ^ V! H: n' D4 S - $my_post['post_category'] = array($cate);
4 O; d+ F( K ^, g4 G3 G - $my_post['tags_input'] = $tags;
3 j* g; g7 I. W4 j# K - //$my_post['tags_input'] = array('tag1', 'tag2');
+ Z2 i# W. f. J; c9 q; I9 M. b5 ~0 v - //$my_post['post_status'] = 'future';0 o' i/ G% a; j
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
6 O( h0 k: |, p) f' {, J9 T H
0 E2 e5 W& Y7 T- // Insert the post into the database
* i' R; u5 t: n - $ret = wp_insert_post( $my_post );
9 w* R( u0 @ c/ D1 h - echo $ret;8 j6 E' ~ j+ ?- ?7 K* [
- ?>
1 {) }( q, o/ L/ h3 r
复制代码 我自己写的
% e# N4 j$ a( A1 R6 q1 I插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|