|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 # S1 S/ s/ d: l4 g
8 Y7 y8 O+ c4 R8 J
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
( l( v" A4 X9 m( e4 m: Y* k ]! A! h; ~ i) }! i5 L4 _
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了 y! i I0 q" `6 N, k/ m; o+ s$ M: Y" K
' t: c. l3 A" l8 c方便实用 简单 何乐而不用呢- : L; O( M. a8 |7 x. ~
- <?php9 H( H. O, g1 {3 f
- ) Q0 W c$ w& v2 N7 n# T. ]9 K
- define( 'ABSPATH', dirname(__FILE__) . '/' );) e! k3 @3 ]; G2 \! S& _
- require_once( ABSPATH . 'wp-config.php' );
; Z% Z# o' ]4 d" h3 N7 y& E j - require_once( ABSPATH . 'wp-settings.php' );
6 N! [0 P4 q# G - require_once( ABSPATH . 'wp-includes/class-wp.php' ); L5 q$ A' |/ C* k# y8 c2 N
- require_once( ABSPATH . 'wp-includes/functions.php' );! s) e: H3 i7 }$ K' c+ Y4 I
- require_once( ABSPATH . 'wp-includes/plugin.php' );
! ~" |! } n' H$ A) { - $title = $_POST["title"];
# C1 ~4 \7 P1 L- p( N - $content = $_POST["content"];
3 O, p# M; u* i; A - $tags = explode("_",$_POST["tags"]);
" x0 Z) |5 y4 r! A2 X - $cate = $_POST["cate"];
) q! g" f$ T! R. k$ Q - //print_r $tags;
; c# X0 l3 q! Y5 ?" c; e9 D1 I. h, g - //
7 h8 w1 m5 ]1 F - //" @! \" o f) K2 x+ C9 }
- $wp = new WP();
: y% v7 s8 d! t" l* R6 t - $wp->main();% \5 z) ]* L7 f
- //
8 k t+ d5 q4 N - $my_post = array();4 {& u) f- i; S$ N7 ^/ t/ R0 X1 E
- $my_post['post_title'] = $title;
1 u* W/ m) t: S* @# @, j - $my_post['post_content'] = $content;3 e% \/ j/ x8 c; ^2 M. o! c2 ]9 {
- $my_post['post_status'] = 'publish'; `/ m; i0 }" O# V
- $my_post['post_author'] = 1;
5 |, |; B2 l6 x4 f9 z9 Q$ `& i2 x - $my_post['post_category'] = array($cate);
4 r* Q" R; N6 B8 M - $my_post['tags_input'] = $tags;
# }& i/ {, [+ I& C. W+ ^+ S - //$my_post['tags_input'] = array('tag1', 'tag2');8 F2 [. g) o7 v/ x1 R9 {
- //$my_post['post_status'] = 'future';
) b4 j3 S& d9 m - ////$my_post['post_date'] = '2010-07-04 16:20:03';0 H; e/ Y8 v g% E7 U6 M, T5 k
7 r' R v' h* b, S+ _) Z; V: o- // Insert the post into the database8 X7 P, p1 K K& E0 ^3 m, y0 i
- $ret = wp_insert_post( $my_post );3 P2 S' z* ^0 P5 K
- echo $ret;$ p7 [5 R! R0 ^/ ]/ O1 H; C
- ?>4 c! W' N. l# J$ F3 z
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
3 b) p, Q; ^/ b- K- <?php" Q" w9 N. \% l! K
- define( 'ABSPATH', dirname(__FILE__) . '/' );
6 K7 k/ r& N: f5 r( o& P - require_once( ABSPATH . 'wp-config.php' );. p9 R$ o$ H4 E; H% `; q
- require_once( ABSPATH . 'wp-settings.php' );
5 {9 i" |2 ]- E- j) y8 O - require_once( ABSPATH . 'wp-includes/class-wp.php' );
8 Q: \0 b6 M+ n6 a S M7 e$ y ? - require_once( ABSPATH . 'wp-includes/functions.php' );
) D( `9 @3 @1 C" d/ O8 u - require_once( ABSPATH . 'wp-includes/plugin.php' );
* V$ T8 \3 M7 m7 ] - $pic_name = $_POST["pic_name"];
' |3 _2 ~0 r/ W- \: y - $pic = $_POST["pic"];$ b% Z2 v/ M, C' F8 g: Z
- if($pic != "" && $pic_name != "")+ G: ?0 S7 M) i- E+ ?/ L5 \
- {% o. H; Z: |$ {( k( \& e3 i
- $path = "images/";( h. t- \0 c3 X! e
- $pic_name = $path.$pic_name;
- ^8 G% K% U2 Q" E& v* D0 j1 K! b - echo $pic_name;
* e5 u( e8 F4 Y - echo "||";
; k* y3 O8 a' a8 M - error_reporting(0);/ ~. b4 S" n) y, H G
- mkdir("images");! L/ y) {4 k& d: e2 g" _" V
- $handle = fopen($pic_name, 'w');! A5 e6 \+ C. E" g9 I0 t u
- echo fwrite($handle,file_get_contents($pic));8 T+ K U* g% j" I2 [- M- Y
- }9 N& Z4 @2 Q8 H
- 7 C# t& y$ K1 q$ @
- $title = $_POST["title"];
; Q h5 K* |( S9 Z - $content = $_POST["content"];
( K! U, @# B( R - $tags = explode("_",$_POST["tags"]);
! C( C7 l6 H; J. ~$ o' H - $cate = $_POST["cate"];. B9 M5 K8 H7 a, }+ c6 X
- //print_r $tags;
( V6 T, W$ \6 o) A4 G& h1 ~: c4 E/ ?6 f - //, I/ a0 A" r7 X, U1 \' ]7 \: I& L ^
- //- H" } Y# @5 a* S6 I
- $wp = new WP();
' s' }2 D! b* _+ F6 ?8 x8 J2 H - $wp->main();
% n! b1 j8 l3 _2 v0 f1 l( C - //
* D5 p- F7 p1 Z% w2 A! t2 K - $my_post = array();1 Z+ i0 k+ Z0 T, U9 @' K8 K
- $my_post['post_title'] = $title;9 q0 M" e* e8 q
- $my_post['post_content'] = $content;
5 N$ W+ N+ F7 _0 y' V( f - $my_post['post_status'] = 'publish';
* n4 L* \$ i5 C" x4 }; R7 l - $my_post['post_author'] = 1;
9 z5 I8 p: P/ n7 o: V - $my_post['post_category'] = array($cate);& m5 j4 V3 d) p2 c! m+ N( j" N9 }
- $my_post['tags_input'] = $tags;( u1 z$ R$ `7 V
- //$my_post['tags_input'] = array('tag1', 'tag2');
$ ]( i" G6 V- X - //$my_post['post_status'] = 'future';
~3 Q4 g* T( ~) V5 J2 H - ////$my_post['post_date'] = '2010-07-04 16:20:03';; M `* R# R. W/ O: r
- . P2 c b8 c; U5 s; A; I- c f
- // Insert the post into the database$ d! R+ q3 g, R
- $ret = wp_insert_post( $my_post );
/ N3 d* _: K$ ~$ f0 K - echo $ret;$ D% C4 ]+ G; Z/ I" X, D# P
- ?># W! X0 _) c$ G; u) d$ B, U
复制代码 我自己写的4 d. P7 j C6 b' p# i5 G; O8 R
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|