|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
6 g3 K7 b+ O4 _2 g+ v% k1 V7 @6 j, I; W, k; c
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
1 x. |$ r) b. Q9 p2 H2 j7 \" e8 u3 o1 h4 b% S6 ^( L
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了7 A( b/ t. J4 E E+ u( ^
& v# V% O+ E* Y! a# e5 q% o* h4 p方便实用 简单 何乐而不用呢
- L7 ]7 b0 o" c- k1 @- <?php; K5 _5 u5 x% Z) d t5 C9 G6 P
1 a! K, K, ]+ c* \5 t4 h$ n0 ]& Q- define( 'ABSPATH', dirname(__FILE__) . '/' );
9 f# E8 v7 M6 C* `& l( ^. w8 X/ Y - require_once( ABSPATH . 'wp-config.php' );# j7 i3 E# Z$ a% O1 K. r. |
- require_once( ABSPATH . 'wp-settings.php' );2 y( z4 G/ I+ h2 h2 V+ D
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
) \6 @3 o$ {# }% S - require_once( ABSPATH . 'wp-includes/functions.php' );* T; Q6 V$ Y$ B$ ]
- require_once( ABSPATH . 'wp-includes/plugin.php' );
1 m8 ~* A' Z9 c/ n& C6 e/ W - $title = $_POST["title"];6 A: f7 d4 i$ U+ W. K, y
- $content = $_POST["content"];+ s! _' H& A3 l% H
- $tags = explode("_",$_POST["tags"]);& O' d6 C7 U) {- c
- $cate = $_POST["cate"];
* N/ O6 ~; [+ ]8 L& L0 U - //print_r $tags;0 `% X0 R L/ w0 q% }7 q
- //# Z- ^1 p3 Q5 o1 ]
- //: a1 P( f* [" G0 F5 e
- $wp = new WP();
4 u& j; {$ |/ Y8 _2 j - $wp->main();; R' K! u) p. i. r( A: M9 k
- //
* r" d$ t2 U2 O& ^0 q4 b8 ~" p - $my_post = array();7 S# S8 [: k" r1 _
- $my_post['post_title'] = $title;# k' p; m5 G: d8 K+ R
- $my_post['post_content'] = $content;
0 t k& \6 V* e) C- b - $my_post['post_status'] = 'publish';2 U/ R1 m+ N) W8 }
- $my_post['post_author'] = 1;/ w/ r# w' p( }7 s6 d" b1 ^7 z
- $my_post['post_category'] = array($cate);
3 h6 V( w) a: o - $my_post['tags_input'] = $tags;
4 p) ~) V: @( x( u$ P; R - //$my_post['tags_input'] = array('tag1', 'tag2');3 T) e' Y+ i6 n' D
- //$my_post['post_status'] = 'future';
G0 l, M) K; V6 [9 m - ////$my_post['post_date'] = '2010-07-04 16:20:03';/ t* b% l, ~9 W' x9 T' H; a
5 P3 e- ]& a$ W- // Insert the post into the database) Y, X' K. a" L
- $ret = wp_insert_post( $my_post );% V% k6 A0 h) c# a
- echo $ret;* T# Z* @! O4 h! s% ?
- ?>8 j! K- ]+ k J1 h E
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
- W0 n3 k, f0 f- <?php$ K' P6 ]' ]: _, C" Y
- define( 'ABSPATH', dirname(__FILE__) . '/' );
. @5 ~" Z- q- ]5 a: B - require_once( ABSPATH . 'wp-config.php' );
4 x5 G) _' H6 n8 Q - require_once( ABSPATH . 'wp-settings.php' );
" X( J* {6 i6 q. l" r! c - require_once( ABSPATH . 'wp-includes/class-wp.php' );
; P; l! E3 L8 M1 ]3 h! {" _ - require_once( ABSPATH . 'wp-includes/functions.php' );
' G2 s; A2 y, R6 I$ W$ F$ }+ Y( \ - require_once( ABSPATH . 'wp-includes/plugin.php' );
, X: p1 v- X% m/ X3 \1 [3 j! \ - $pic_name = $_POST["pic_name"];
/ _ v" a w( A+ W - $pic = $_POST["pic"];4 `2 s" @8 ?, _0 z4 ?, o' n
- if($pic != "" && $pic_name != "")
( X* B' |+ e, I, o - {# _/ f8 V6 ^3 r1 Q, l
- $path = "images/";) \& H8 G# Q5 v6 d
- $pic_name = $path.$pic_name;6 f+ I/ U9 N+ |' ~6 x
- echo $pic_name;
8 ]9 P* t$ e4 D4 k6 J5 f' X& Y: a - echo "||";) O4 d- M. U- s. T
- error_reporting(0);
) @1 I( r1 a5 j: e - mkdir("images");$ a( b$ V( d, F
- $handle = fopen($pic_name, 'w');+ F9 H' [* Y3 G
- echo fwrite($handle,file_get_contents($pic));
5 g& |' r4 S2 K4 W, S$ Z% \ - }, J+ H. m. K3 N4 f$ z& e
) K2 j$ i% V( e$ z6 h) M- $title = $_POST["title"];" l+ k% X8 G1 p: {! ~6 k
- $content = $_POST["content"];
0 e2 B1 s9 _+ I/ b - $tags = explode("_",$_POST["tags"]);
- B. r; t' Z+ H) e! |% T: b - $cate = $_POST["cate"];' e0 ~! e; A6 Q4 x! ?
- //print_r $tags;
2 K U/ v# A( D3 ~ - //9 m( m( c8 }1 O& x1 ~0 h& u7 _% ?1 j
- //
& p7 L+ P" x4 r% |9 E6 A# v - $wp = new WP();; y5 h$ U+ N+ Q6 [% o% | E
- $wp->main();% d2 T' g+ @" N& O7 @4 d
- //
4 ]3 |) L/ I) s4 L8 D' y. | - $my_post = array();: ~, M: c; U+ S: [, k$ @' v
- $my_post['post_title'] = $title;
1 a0 I0 B8 X* L4 n! H - $my_post['post_content'] = $content;& y- e0 x6 c+ x3 W# |
- $my_post['post_status'] = 'publish';# L8 r. {' f2 F% u% B J
- $my_post['post_author'] = 1;
7 L: B( {$ G+ V - $my_post['post_category'] = array($cate);+ x% V/ I% X( n X6 U$ ~+ Q0 h0 @
- $my_post['tags_input'] = $tags;
2 [6 q y3 ?, w, } - //$my_post['tags_input'] = array('tag1', 'tag2');! n1 J8 l' h# S; n
- //$my_post['post_status'] = 'future';1 N) ?8 ~; g* j8 H1 F3 G: ^9 V' W7 R: Y
- ////$my_post['post_date'] = '2010-07-04 16:20:03';# O& a# U# w c: `6 {3 @4 I% R
- 1 n+ M4 H) e* x9 C
- // Insert the post into the database
5 W6 r W0 w+ M% C - $ret = wp_insert_post( $my_post );
; M% g- }. W7 q/ N. n - echo $ret;1 g4 d6 O/ m! X4 j; @1 Y1 l9 U
- ?>
( I: d2 f- n' B% w% d
复制代码 我自己写的: N; N6 y/ r3 S
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|