|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
4 h3 @6 s) w& B- ]8 ~/ i' O4 j# _' b: b* V! p
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持4 `$ w4 `& X$ a& c& V
! T; ?, _5 C. [: _- K5 {我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了# m# a) \; w! W4 _, |7 `
% n; {. [& [( r3 P
方便实用 简单 何乐而不用呢
0 H) q5 c. v/ q, U9 Q$ U, o0 g, H- <?php
* @3 Y3 w4 d c2 i4 n2 Z
* }' _. w8 e% x2 S8 u- define( 'ABSPATH', dirname(__FILE__) . '/' );
9 t6 e% D/ _! r - require_once( ABSPATH . 'wp-config.php' );5 Z, f3 t, K7 O$ V- Q/ c: M
- require_once( ABSPATH . 'wp-settings.php' );3 [% o8 G1 T: h
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
7 Y' f& G( `. `/ n/ D, |0 O8 x - require_once( ABSPATH . 'wp-includes/functions.php' );5 N. C! K8 G% t& v; J* I
- require_once( ABSPATH . 'wp-includes/plugin.php' );6 w% a c' b: T/ |7 W- M
- $title = $_POST["title"];! r1 _2 N4 t6 r; R
- $content = $_POST["content"];0 [, o' v6 d3 a' H1 U
- $tags = explode("_",$_POST["tags"]);& q- i# r% a0 x
- $cate = $_POST["cate"];
* `& G y, E3 J# w, F0 N - //print_r $tags;' `; X' ~0 C. x6 A' U! F
- //+ y3 |7 L& h. s* u3 F/ _, z
- //5 B/ `. F% d, T0 H
- $wp = new WP();+ B0 F0 p$ S0 T' S8 |
- $wp->main();; d4 {- f* m/ S9 Y
- //, `$ O7 J/ n g" F
- $my_post = array();& f7 U; O U& d1 M5 R
- $my_post['post_title'] = $title;! P; Z) o( u" \8 Q; T. b$ P6 a
- $my_post['post_content'] = $content;
: ] _+ C3 E) w: F - $my_post['post_status'] = 'publish';
) R# W: ^/ t3 D/ n - $my_post['post_author'] = 1;
; ^/ }8 h$ e7 \+ h$ n4 e6 `- S: M - $my_post['post_category'] = array($cate);
) d6 X5 t+ N% o* e! @ - $my_post['tags_input'] = $tags;, |% B# I; I. w' @. w
- //$my_post['tags_input'] = array('tag1', 'tag2');' y0 g w+ J6 ^% c0 G) J1 {
- //$my_post['post_status'] = 'future';2 T- H# A" k+ Y' u. b& p
- ////$my_post['post_date'] = '2010-07-04 16:20:03';; r7 D% S* K' k' e& }: R" }
- * X3 v% o$ s% j q1 B, V
- // Insert the post into the database: [ ` c: m+ y# r7 W7 |
- $ret = wp_insert_post( $my_post );
! v5 P9 e; y4 \7 |8 o. V: ` - echo $ret;$ i" r) v" @! S- u
- ?>
9 U+ b; p: ?4 P! r, `; E
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ( d0 Y8 V. D: j! T+ {) M& o
- <?php) i" y" z# X3 {1 n P4 V
- define( 'ABSPATH', dirname(__FILE__) . '/' );4 B& ~& g( d) s! x; {( A
- require_once( ABSPATH . 'wp-config.php' );/ H' U* S; n. m3 x$ v, W' W& O
- require_once( ABSPATH . 'wp-settings.php' );
4 g' t. q. Q- Z- k - require_once( ABSPATH . 'wp-includes/class-wp.php' );* }8 K5 E% U) ?4 I' c
- require_once( ABSPATH . 'wp-includes/functions.php' );( V& ]( S; J9 O' X6 F4 O3 f
- require_once( ABSPATH . 'wp-includes/plugin.php' );- W3 H# V" `1 O8 W: ^* f
- $pic_name = $_POST["pic_name"];
' Q0 g o% ]4 \! @3 h - $pic = $_POST["pic"];' f8 u$ I6 q8 {. @8 V0 A
- if($pic != "" && $pic_name != "")
& @: V2 [6 ?! }, ? - {
( L8 G7 c9 Z% `& _' E4 K - $path = "images/";
& w, f3 Z1 X; f: Q5 ] C. q8 Z - $pic_name = $path.$pic_name;
& o9 l) }# I0 s* R1 C+ e - echo $pic_name;4 o; L. ~7 E) T& B
- echo "||";
0 \1 g! m0 H$ ~! K" \/ H+ ^4 B - error_reporting(0);
2 ?+ O L* M# P+ B u5 K - mkdir("images");
$ f) ^; X; }- C5 a" A+ I- E9 ? - $handle = fopen($pic_name, 'w');5 ~8 d H. n% B9 A
- echo fwrite($handle,file_get_contents($pic));
1 q V w. \7 \) p D - }
8 @' v. J# N3 v; H3 {$ x6 {
7 T' |. r# L& |- $title = $_POST["title"];. M+ n% y- |8 M/ H, u; j" r5 Z
- $content = $_POST["content"];
/ ]& q9 m1 _# G - $tags = explode("_",$_POST["tags"]);% q; @) a' J% G, ~9 v' c' m; W$ ?
- $cate = $_POST["cate"];
6 S! R9 C5 z0 E! ]5 t1 \# u - //print_r $tags;4 p+ w8 e' E+ }5 ~! w% E
- //
$ D+ c3 Q8 N! x6 H - //! W7 V+ Z4 ~6 k: w
- $wp = new WP();4 M: X" j! J. W; C1 n' \. Z/ `
- $wp->main();
- ]: _/ b; u. O) ? D6 f2 D% } - //
5 P/ I* K& r- k# K6 k3 ]' R( a - $my_post = array();
8 A$ f3 p, J1 E - $my_post['post_title'] = $title;
& F8 P" b. }. S; C/ w( E8 Y) D - $my_post['post_content'] = $content;2 n5 M e, C/ _ J. u+ l
- $my_post['post_status'] = 'publish';
6 P3 d, k5 |$ P- X - $my_post['post_author'] = 1;, E @0 ^+ A. N8 U' K% Z
- $my_post['post_category'] = array($cate);# Y8 [* @9 R3 |; B
- $my_post['tags_input'] = $tags;
: }5 H1 a: Q4 U( @ - //$my_post['tags_input'] = array('tag1', 'tag2');. U$ O( Q/ J" B
- //$my_post['post_status'] = 'future';# e$ }* L9 Y! j! R6 o; e
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
! M! U+ p/ ~" K# D
; ^; A9 o: O& L) o6 _" H1 b3 m$ Q$ @# V- // Insert the post into the database
& w6 V. h0 E `; x+ w# S - $ret = wp_insert_post( $my_post );4 n8 }/ T E3 U" |) W' e: ~) H
- echo $ret;
h9 j d1 H( b6 y' U w - ?>
v4 ?$ e( H: R, }+ Z
复制代码 我自己写的1 n0 d0 H# f6 p, c5 `( U
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|