|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
7 ]+ f9 Q5 h. v: z w8 H% {% T- J# T3 M+ q
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
% v& G/ V4 q. v1 R: D9 S _) c- Q3 O7 V7 X+ j( R
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了9 g4 p& ~- ]6 F5 D( y
0 E* g6 `% e$ T$ I" c方便实用 简单 何乐而不用呢- / O) o+ k) z; |. d! Z' h
- <?php/ f* F0 V- t; Y' m5 d0 c
- ; R; ]. [7 j7 Z# y
- define( 'ABSPATH', dirname(__FILE__) . '/' );; S2 P* ^/ r$ X
- require_once( ABSPATH . 'wp-config.php' );
4 Z! U( K& i8 a - require_once( ABSPATH . 'wp-settings.php' );# h9 V% g, \4 ?* U
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
y2 P: _! w; U6 a/ x! [/ Y - require_once( ABSPATH . 'wp-includes/functions.php' );
' B% B" b: p. y" V - require_once( ABSPATH . 'wp-includes/plugin.php' );
5 ^& Z2 Z$ W- ~9 s - $title = $_POST["title"];
2 w' n8 e0 s/ i1 q. P7 Y6 q5 D0 f - $content = $_POST["content"];
3 h4 u# T3 g o& e/ ]& ~& E - $tags = explode("_",$_POST["tags"]);
: B; o$ h+ i1 W1 b3 ^% ^# D* G0 M - $cate = $_POST["cate"];
' D$ w( E4 L! ? - //print_r $tags;
% | G3 Z( l# O8 Q: K# F - //
" Y8 }( t4 p1 c6 \! q1 T( N - //, ?3 F* u$ A; r
- $wp = new WP();5 o$ R) y& b6 y* ?
- $wp->main();
: }% J; N9 u, k: t9 d/ e x - //' S7 t3 J" u5 }! D
- $my_post = array();1 y1 @1 A# U+ e, H
- $my_post['post_title'] = $title;: n$ n6 \- P. _* Z! \7 I
- $my_post['post_content'] = $content;0 }2 s+ |9 K1 p) c* e* P, i
- $my_post['post_status'] = 'publish';
2 t5 F8 b7 A5 X: L6 u - $my_post['post_author'] = 1;3 E3 q( w0 I' ~, _) _* \- _4 m
- $my_post['post_category'] = array($cate);
+ o( R& T% Q6 v8 z, k- L5 Q6 Y - $my_post['tags_input'] = $tags;. @5 g* X; W7 D/ m8 k1 t% U
- //$my_post['tags_input'] = array('tag1', 'tag2');
. y) t" F2 N5 q+ g - //$my_post['post_status'] = 'future';( ]* {/ \3 Q' j1 O- T% X
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
" G3 ?9 F' u9 f( {+ d
0 Q; z H& G( m0 ]9 }- // Insert the post into the database
/ Z; Z: N; U$ m/ [* @- U x - $ret = wp_insert_post( $my_post );
2 ?; w& o; G4 L: N+ j% J7 o - echo $ret; j9 ^) u& M' z: l" G
- ?>
% k$ K. o5 y0 s# ]; q! a
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- : Y {& m- a: ~" k0 ~
- <?php
. U5 v3 Z$ }1 Q - define( 'ABSPATH', dirname(__FILE__) . '/' );! Y0 Z" Y! {' q" z
- require_once( ABSPATH . 'wp-config.php' );
! s4 |) B! c& A! z/ G0 x0 B - require_once( ABSPATH . 'wp-settings.php' );# O! W v8 a5 C% z6 b7 }/ B
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
. a- s8 }& U: q @8 S) y% B - require_once( ABSPATH . 'wp-includes/functions.php' );2 i: D9 l$ r% \( K1 K
- require_once( ABSPATH . 'wp-includes/plugin.php' );) l; ^ F6 ] l7 w6 d
- $pic_name = $_POST["pic_name"];1 B+ d5 ?8 u7 x+ ^% o
- $pic = $_POST["pic"];
% t9 p9 ]' ]* Z# V9 M- q - if($pic != "" && $pic_name != "")
! _/ K7 H4 F9 x - {% g6 N0 R* x7 U: `, u
- $path = "images/";
f# ~$ d" X9 }' M- G: Q - $pic_name = $path.$pic_name;* @ D7 v0 N% r6 L3 R }/ @' L* Z
- echo $pic_name;
9 {9 J' S, B+ o$ X+ @% G - echo "||";
( R" L e( C# q& D" G4 o - error_reporting(0);
- s3 y) B, ~7 X4 Q' M - mkdir("images");& l7 F& _4 Y: y' a5 W3 _
- $handle = fopen($pic_name, 'w');7 i4 B) z5 S# V& g# s8 S/ E8 _4 p
- echo fwrite($handle,file_get_contents($pic));
" c9 D- D% X3 y1 ^1 A - }
( K1 y4 `) z5 z/ M" q: t+ N1 ~
~1 M/ o) R8 u1 A) k) F: w- $title = $_POST["title"];" G$ z% G% z; {$ n% P! S2 p/ m* Z
- $content = $_POST["content"];
& F O4 `. n5 k: }- W* g - $tags = explode("_",$_POST["tags"]);6 t! D k {0 \! ?" I6 I% }( f& B9 l
- $cate = $_POST["cate"];/ ?( G5 R/ w: R' z5 a; h$ F
- //print_r $tags;
' i9 {5 X0 M! ^- d8 V7 o - //. t: C% r- Q' ?
- //, o; w# i! o, q- s
- $wp = new WP();
! {. _/ m& X. \& Y - $wp->main();7 e0 f! Y4 w) ~% k
- //# e( b8 y) d/ _1 X( v9 n! q: P% M
- $my_post = array();
% s" ]* G r$ j' o - $my_post['post_title'] = $title;' d1 f! H/ l, H0 c9 u$ b
- $my_post['post_content'] = $content;2 o* i" C, h2 x
- $my_post['post_status'] = 'publish';
7 _! W4 b# A4 q- b( R }; | - $my_post['post_author'] = 1;
: Z2 g8 ^* ]# w1 q$ |" N" r$ n6 }/ f - $my_post['post_category'] = array($cate);8 Z# p0 z, H: K% S2 J) W5 {
- $my_post['tags_input'] = $tags;- I3 `( p$ _. ?5 L& e; b
- //$my_post['tags_input'] = array('tag1', 'tag2');' D9 B$ b" D8 f. Q- ]
- //$my_post['post_status'] = 'future';7 W2 d7 H" ^' j+ O' q6 T9 j% [2 N z
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
$ ]$ V3 H! n# n- c0 n" E% P - # `9 L' J* k4 F- ?0 j
- // Insert the post into the database. b' w/ g4 W3 {! K: X
- $ret = wp_insert_post( $my_post );
9 K* [6 J+ L6 P( {1 ?1 v - echo $ret;
6 ]$ m) J9 o# S( E; V- k5 v$ n1 L - ?>6 G. u, i G( R4 D1 S* y; p5 Z S9 L
复制代码 我自己写的
8 @6 W' k$ t( t `插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|