|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
) a6 F% T3 E5 h1 {7 `# i: w/ H, y! B- R3 g. M3 l
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
, m+ b Z9 Q* F4 N! Q; r- g' X* d7 Z6 t9 u) u) j3 }
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了: Q" j7 s* _7 ]
$ s( H* Y3 C( |) y0 g* ^8 c _7 K8 T
方便实用 简单 何乐而不用呢- 6 i% f F% f) ?* ?7 Z6 Q
- <?php
$ i/ S. L% ~* N" h+ d8 }6 v( _# T" f - & S! m' F/ U5 _* m. b) G/ I, ?
- define( 'ABSPATH', dirname(__FILE__) . '/' );1 I/ t# E0 C% y9 c) P& W z7 `
- require_once( ABSPATH . 'wp-config.php' );4 g7 r. F9 w% _4 G
- require_once( ABSPATH . 'wp-settings.php' );, z# U! ~" k( R# c- ]4 T% z+ W: u
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
5 y" p/ m9 E3 g0 ^ J G1 B j - require_once( ABSPATH . 'wp-includes/functions.php' );. G- B U$ C) ~) @1 f) U5 }
- require_once( ABSPATH . 'wp-includes/plugin.php' );8 M8 b( K+ N6 R3 A
- $title = $_POST["title"];
4 v' ]' L7 ~, f9 ]$ `2 g2 g s - $content = $_POST["content"];3 L/ o2 p+ @0 y# h% e
- $tags = explode("_",$_POST["tags"]);# O: D2 R" Y H H: l* A# Y+ r
- $cate = $_POST["cate"];
1 q5 L- b* _" v/ @. P; a - //print_r $tags;* x- o/ c# S' ?1 u
- //
% _! A' I! ?1 E% u5 D5 [4 f. S8 F - //* U9 O5 k, G- w9 y7 i1 Q
- $wp = new WP();
6 u1 [3 x9 N; C# P( p - $wp->main();+ X+ b" D" x7 y/ i" j3 l+ P; O+ K+ G
- //
" r5 l3 T0 M$ i/ w: j& Q, ^. s, e - $my_post = array();7 c! c* Z/ q- I: U+ F) B0 H5 J0 r9 D
- $my_post['post_title'] = $title;
( j& i- Z2 y8 [0 S2 a9 E: [ - $my_post['post_content'] = $content;' G# x+ h3 d/ ` O1 x1 |/ i: I
- $my_post['post_status'] = 'publish';
6 x7 ?3 ]7 s0 e$ v+ W( x3 g% f - $my_post['post_author'] = 1;
+ I. h: Y5 b) r1 i; D$ P' O! \; M - $my_post['post_category'] = array($cate);
1 W0 I8 w$ |; \) N& M - $my_post['tags_input'] = $tags;9 o8 P& U/ m+ M6 ?" B) `
- //$my_post['tags_input'] = array('tag1', 'tag2');
# }3 y: S2 U V; a/ s - //$my_post['post_status'] = 'future';
& |, p. e) Y* M" r4 k - ////$my_post['post_date'] = '2010-07-04 16:20:03';0 s1 x+ ]' }! k6 ?' V8 v& N! f* {
/ Y5 O) O/ C, p t4 g" H3 f- // Insert the post into the database2 d0 G1 ]% F" o4 @* W; R
- $ret = wp_insert_post( $my_post );
2 l% ]: @7 \8 h6 J8 R1 P - echo $ret;
. F4 ?$ a+ k5 a$ [5 {; z! u6 [* b2 b - ?>
( G) s) C4 z( `+ O
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ! D$ X; U# Y. m! X& ?$ X
- <?php) F# g |, t% j5 q$ d: Q* H
- define( 'ABSPATH', dirname(__FILE__) . '/' );4 q# r0 S& X3 ^2 Q0 j2 I% `9 S
- require_once( ABSPATH . 'wp-config.php' );
( H6 }! E4 B8 Q/ T% v9 ? - require_once( ABSPATH . 'wp-settings.php' );
6 M/ Q3 X% y5 _: q( m& K3 x - require_once( ABSPATH . 'wp-includes/class-wp.php' );; r5 D3 b8 L8 u( g
- require_once( ABSPATH . 'wp-includes/functions.php' );
2 }, c& ?: Q. Q0 N& e - require_once( ABSPATH . 'wp-includes/plugin.php' );
2 E/ u. w+ F$ R; d7 e! L7 J# d - $pic_name = $_POST["pic_name"];
, c( M' ^. ?6 \1 }0 ^* d - $pic = $_POST["pic"];
+ w0 I' f8 w0 V$ T# Z; e0 ~; a" x - if($pic != "" && $pic_name != "")+ K8 I% ~1 `/ ~2 |% g
- {
& s# V8 ?5 z$ H# A q+ C - $path = "images/";7 d; C& P" t* B: E
- $pic_name = $path.$pic_name;5 S2 K5 ]5 c3 M0 R5 c4 u- f! Z
- echo $pic_name;5 o q' ^# G9 l( L& u/ ~
- echo "||";
6 R2 M) w5 _' Z/ N- I1 x# T - error_reporting(0);
, m$ {* n) K4 l6 D2 u' R - mkdir("images");
* L3 J) x6 R/ w+ _* p9 z - $handle = fopen($pic_name, 'w');% z" b* F+ C8 V1 r/ H
- echo fwrite($handle,file_get_contents($pic));+ O7 M, d7 ^; t9 ~
- }3 a) H% I+ P3 E
- : w- z- {+ ~( r' n& m/ Z
- $title = $_POST["title"];
& z7 ~; z+ j8 P! D$ t6 L1 ? - $content = $_POST["content"];
4 n, a2 x H& y C, O/ P% \1 H! K - $tags = explode("_",$_POST["tags"]);
. d: y1 Z& Y6 I& V4 t' v/ e - $cate = $_POST["cate"];& p+ [3 @/ f# @( M
- //print_r $tags;, [: V2 A- J( h! d
- //
1 s# T$ ]( d; H! L& D/ j1 Z; R0 p - //2 e7 ^. ^* t" F8 K
- $wp = new WP();3 R, h- `5 l3 I8 E
- $wp->main();$ j- V& |4 ?3 U) A& S$ w" z
- //
3 {) ]! G2 P" ~; w, `% w3 w9 n - $my_post = array();4 @& T# J( |/ \4 Y' c/ |. I
- $my_post['post_title'] = $title;
9 \" h( N* ?& Z Y* M- ^, D$ G - $my_post['post_content'] = $content;
* s# f# B. m) _* Q6 A( a X - $my_post['post_status'] = 'publish';
; Q7 O& W/ L. o$ e) q1 j3 l - $my_post['post_author'] = 1;' }3 |% F3 m+ D) Z/ T5 P
- $my_post['post_category'] = array($cate);
$ H% j+ T; ?( D, Z4 ?5 k - $my_post['tags_input'] = $tags;/ \7 H- ~" @& n3 m+ a
- //$my_post['tags_input'] = array('tag1', 'tag2');
- u- a. Q/ X! h+ c6 n; C: j- C - //$my_post['post_status'] = 'future';% y G8 |1 G3 o* ?2 C/ Z
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
3 R" r, w. d3 S+ m0 l) r5 X - ( R# t q, K) _; B* Z
- // Insert the post into the database% i6 p3 @: _7 h* y- o
- $ret = wp_insert_post( $my_post );/ }6 r& \! |8 D, N3 r* {% A
- echo $ret;, [1 a6 w# x/ N0 o6 B% g D/ b
- ?>
* R8 x+ M3 X* y% c) n1 m; F
复制代码 我自己写的
: o: T) ?: i( i+ T- W5 K- _" c插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|