|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
+ H3 l; x/ g1 W0 @: ]. K# P- U8 D/ ~3 [
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持* V3 V- K/ p! r; V) G$ A: C# m
9 R, [5 p# w( ~; ]' O! {, E2 [' o0 o
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
% p& z Z# v6 P+ m
; p9 }- n, K4 j$ n4 P方便实用 简单 何乐而不用呢- 3 h) e* o% k4 I2 H2 f0 l7 `0 m
- <?php6 n/ k6 V% ^0 X/ Y+ d
- % O$ h; r- Q# C. O. c, x
- define( 'ABSPATH', dirname(__FILE__) . '/' );
2 ^" B% b3 ~4 b# R - require_once( ABSPATH . 'wp-config.php' );7 i% ^# ~$ x: i9 t( n0 T1 r6 B. c8 g
- require_once( ABSPATH . 'wp-settings.php' );
6 L1 X h! x. a' e$ w# m* q - require_once( ABSPATH . 'wp-includes/class-wp.php' );
, Y2 Y2 `- Q9 p( i& ^ - require_once( ABSPATH . 'wp-includes/functions.php' );
: W6 o. ~" m( ]" X$ g! D! n - require_once( ABSPATH . 'wp-includes/plugin.php' );0 n3 K+ S, t z) \) q5 ~
- $title = $_POST["title"];9 I' [2 q3 Z9 Y) z6 |, `
- $content = $_POST["content"];: ^( y' v z2 S. B# m; D
- $tags = explode("_",$_POST["tags"]);
* r4 F+ P* q) U8 \ - $cate = $_POST["cate"];$ a2 @7 n+ `7 I
- //print_r $tags;
U' G. N7 L+ E. _( q - //' ~$ ~$ X$ a) v
- //: |% @ a1 A; i$ ~/ [9 l
- $wp = new WP();- ^; L1 K v. V$ k% g" b
- $wp->main();
" S' A) [' r: X - //" a! f2 c4 b5 O' ^
- $my_post = array();6 P' u) u/ y5 Y
- $my_post['post_title'] = $title;
7 f* o: e! F& e, J* I - $my_post['post_content'] = $content;
' [% O! {5 ^+ q4 {$ r0 x - $my_post['post_status'] = 'publish';
# r4 {1 G# b$ `2 u% g% W) K/ R - $my_post['post_author'] = 1;$ a( u3 X) s7 n- t$ Q+ v
- $my_post['post_category'] = array($cate);3 @8 b6 o7 u! w* a1 p. D1 h1 e
- $my_post['tags_input'] = $tags;
8 c5 y% M0 @! \" B - //$my_post['tags_input'] = array('tag1', 'tag2');
- J M s5 X6 K, Q/ H - //$my_post['post_status'] = 'future';
1 N$ o$ k# @* ^' @+ { - ////$my_post['post_date'] = '2010-07-04 16:20:03';- S- l% p# q: |7 n. b3 ]2 V9 D" B
/ v4 c2 z. r) r' `* E( ^- // Insert the post into the database
/ r( M2 B" ^$ H( _" T. m - $ret = wp_insert_post( $my_post );: U9 b8 i# y. t: ^" M3 `
- echo $ret;% w: g. G- D1 R' j' Q) V
- ?>- Q$ B& X8 f7 G9 _
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- & k8 }+ y3 y& i. ^9 h2 l' _) G
- <?php1 u! F1 v0 t9 Z4 c/ r
- define( 'ABSPATH', dirname(__FILE__) . '/' );
3 I1 R. U+ Y' F! { - require_once( ABSPATH . 'wp-config.php' );" `7 e! p+ I: N: D% M: f
- require_once( ABSPATH . 'wp-settings.php' );" S6 v }3 L) U0 N) I* R
- require_once( ABSPATH . 'wp-includes/class-wp.php' );$ j2 x; j9 ?6 ]7 p( c
- require_once( ABSPATH . 'wp-includes/functions.php' );2 B q7 a W2 q6 S/ u( N7 e
- require_once( ABSPATH . 'wp-includes/plugin.php' );6 F1 {/ x/ w0 y0 m
- $pic_name = $_POST["pic_name"];; G( W8 }4 J' J/ u! u6 X2 ^0 Q
- $pic = $_POST["pic"];, E; p& i' o! a( V/ j
- if($pic != "" && $pic_name != "")
6 c' y1 ~$ i6 [% P: @2 K - {4 Y" Q9 G7 i, s4 A9 Q; I5 ^
- $path = "images/";
R. c: V/ \* }7 C3 c5 o - $pic_name = $path.$pic_name;% E- F9 m( q U! U2 f5 w- E& q( B
- echo $pic_name;
! _3 U) V0 Y+ V - echo "||";
8 v' Z7 _0 K% g% Q' u: Y0 A - error_reporting(0);3 J" H4 n4 ]7 U, R* G3 b L& i/ g
- mkdir("images");$ {6 ^ b& c! ^0 C* O
- $handle = fopen($pic_name, 'w');* A/ z, y) g2 ^2 v$ `3 }) j. M
- echo fwrite($handle,file_get_contents($pic));
0 m1 Q- x: ?$ L, V - } T( y* M9 B0 o0 ?
! e' U) K& e+ s7 s& p9 |- $title = $_POST["title"];$ p6 j9 u7 f8 X1 z
- $content = $_POST["content"];1 b' j0 v( M1 l# f+ m
- $tags = explode("_",$_POST["tags"]);& L8 u% ^) g0 u
- $cate = $_POST["cate"];
& C; J1 {: L# M, n8 P - //print_r $tags;2 `& B1 i [* Y5 ?" P& @2 I
- //4 o% K8 C: T* q k" t/ \/ T+ G% k
- //' R) S. w4 U6 B" _' d
- $wp = new WP();
5 y* @) n! S( T. T2 J - $wp->main();" V* `5 @' C4 O) J: |: `4 y5 P
- //4 D( G9 O7 G7 o0 o( s0 I- d7 a
- $my_post = array();
! u6 n% b1 s% ?' @" ^, A( v - $my_post['post_title'] = $title;
" Z1 A6 |: l6 E3 l - $my_post['post_content'] = $content;
- a" i F5 _/ M8 C2 x4 V9 T4 y - $my_post['post_status'] = 'publish';
7 x; q! w, r4 g: C - $my_post['post_author'] = 1;: r' `3 Z. e" q9 ^. O6 |( e
- $my_post['post_category'] = array($cate);" A( w/ N' r( @; ^: D& R. C
- $my_post['tags_input'] = $tags;4 J( a! b3 d# g3 [
- //$my_post['tags_input'] = array('tag1', 'tag2');+ X7 g: A" A3 F9 `
- //$my_post['post_status'] = 'future';
# i1 n% W% Q: v! C9 H* ] - ////$my_post['post_date'] = '2010-07-04 16:20:03';* g. L$ T' t7 v
* s F' o5 C/ G- B+ y1 `: g+ Z- // Insert the post into the database
# l1 _1 M; Z/ o) u - $ret = wp_insert_post( $my_post );
) R# u( I V+ ~ - echo $ret;
% q+ G" y7 d5 u! W/ b - ?>
# D5 y/ ]. h A9 x" I; w
复制代码 我自己写的
0 ^7 Y1 Y+ c! Z1 d# _$ S3 R插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|