|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
; P, M+ n* y; b$ U, w: r5 b1 h
8 D2 K: o) w8 ~) J直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持- {' ?! ~3 G/ V+ Y! T6 U
0 C- J$ K/ [1 m我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了3 F+ B0 o* Y: z* ~8 ~: T5 X
" {8 a$ |1 y& I6 t
方便实用 简单 何乐而不用呢- ) Y# t* y) }8 Y* O0 q8 _( |; y
- <?php
: `( R5 f! \% J, L
& o2 u+ f t3 v; B! B7 ~- define( 'ABSPATH', dirname(__FILE__) . '/' );
7 a3 j! F6 ^% [ - require_once( ABSPATH . 'wp-config.php' );
4 J( m6 V& p3 S; B - require_once( ABSPATH . 'wp-settings.php' );
$ b& d7 _5 F4 g - require_once( ABSPATH . 'wp-includes/class-wp.php' );
- _$ j; {/ v, p$ R- n+ ] - require_once( ABSPATH . 'wp-includes/functions.php' );
; j! R6 }0 |7 J - require_once( ABSPATH . 'wp-includes/plugin.php' );
# @5 ?) z3 r2 p5 r - $title = $_POST["title"];, h) J& x' {; Y9 S
- $content = $_POST["content"];6 P; ~6 ] P5 ]4 m& ~+ @0 |
- $tags = explode("_",$_POST["tags"]);' v7 i8 Z8 |: S) e/ P5 r- S
- $cate = $_POST["cate"];
* Y0 U+ g0 Q: \2 m4 @' q - //print_r $tags;7 m S' z. E7 \5 F6 F! R1 U
- //
4 N0 Z& O7 U: h: H2 i+ m/ o$ _& g, |5 _ - //
- I' f. F2 T+ r s8 E- j, y - $wp = new WP();
% o' U% N) u+ P; P- k3 ]; z - $wp->main();
# Z# k& y% R8 h1 T* U: N - //# D- C" j+ q' S. n; n$ r0 [
- $my_post = array();
0 m* [6 F7 m- [, Q1 k - $my_post['post_title'] = $title;
% D! Y, K% t3 |( ?* {) U8 q - $my_post['post_content'] = $content;
o! w9 E. L* r* {3 n. q- M - $my_post['post_status'] = 'publish';5 E" h0 E. }1 E. H) F: ~& y
- $my_post['post_author'] = 1;
: V, c+ f: [$ ? - $my_post['post_category'] = array($cate);2 b5 z3 T. c6 a/ t' k! n6 \
- $my_post['tags_input'] = $tags;
% t% W' }3 \5 @- j& b - //$my_post['tags_input'] = array('tag1', 'tag2');2 k6 |0 W$ }& p: `/ j& E1 o: L
- //$my_post['post_status'] = 'future';
5 y# Q. b/ b( q: e - ////$my_post['post_date'] = '2010-07-04 16:20:03';. P4 D: v9 L+ z! J' ^
- ; W* @* s) z) t# c. ^1 X/ y) I/ z
- // Insert the post into the database; ?( R; c$ ]% ?- N
- $ret = wp_insert_post( $my_post );7 K9 o; @( t$ f. k/ Q! N' n7 }/ p
- echo $ret;, Q4 s8 w1 ~+ R% t+ E3 l
- ?>
4 D/ A5 p" m/ j2 V- j
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
$ {4 a; A: B3 e9 p- <?php \. E% o) z4 n. F' t" T' ]
- define( 'ABSPATH', dirname(__FILE__) . '/' );+ n2 T6 M4 U4 S+ Y% u1 q6 [* e
- require_once( ABSPATH . 'wp-config.php' );
* A4 w! v5 H" Y! S7 t5 p; t3 q - require_once( ABSPATH . 'wp-settings.php' );
) _- ~8 O( E" h6 y! ~* P6 L4 K - require_once( ABSPATH . 'wp-includes/class-wp.php' );2 F) w w( o k* m( Y
- require_once( ABSPATH . 'wp-includes/functions.php' );
/ t8 k/ \+ I+ b - require_once( ABSPATH . 'wp-includes/plugin.php' );- U+ l+ Z3 t. [# U4 M
- $pic_name = $_POST["pic_name"];; Z; Q4 Q4 G( `$ {1 A$ [
- $pic = $_POST["pic"];
/ c5 |2 G2 j# p8 O7 D# k - if($pic != "" && $pic_name != "")/ K$ w2 }6 ?; k% T* O
- {
& [9 v# v. d1 |: M- c7 E7 F - $path = "images/";
O7 p1 x7 _! F* @ - $pic_name = $path.$pic_name;: h& i+ R* W) c. v* G% M! P% N( }5 { T5 s
- echo $pic_name;1 x$ J5 R$ `; w# L
- echo "||";
! u) i" N; f2 C, P - error_reporting(0);
) u' ]7 x8 s4 U& |8 F3 _. c - mkdir("images");. V: l: k6 _: e- X
- $handle = fopen($pic_name, 'w');
7 b, S6 u( Q4 ]9 v8 Q - echo fwrite($handle,file_get_contents($pic));9 q6 Z% ?* P* r
- }
+ a4 k/ d' d( j& h- [4 S x2 B& u! V. H
# k4 B, F% {( g, Y8 t- $title = $_POST["title"]; S3 `' B2 B, g' V+ |( l w
- $content = $_POST["content"];" T* o3 ]4 X* z. ~0 S A
- $tags = explode("_",$_POST["tags"]);# Q# N- H p/ `. [
- $cate = $_POST["cate"];% B& d' D2 Z3 L+ P; N, I
- //print_r $tags;
! _8 u. E0 B* k0 I4 Y, y k1 p t7 C- l - //5 O) H) r5 O6 J" o# L5 w7 G
- //
% K( [+ o) F* p - $wp = new WP();
6 w- c4 t1 _, Y& ^" \# o - $wp->main();
6 s# ]# }0 }) L7 Y1 n% [3 C/ \4 L - //
: G" c3 {, m' b! t" f4 ? - $my_post = array();
: Z- M$ C# o7 _" q) ^ - $my_post['post_title'] = $title;' ~8 q3 R# V* d3 f" t4 E
- $my_post['post_content'] = $content;
( p2 \, }/ J4 ], K; a# q- ` - $my_post['post_status'] = 'publish';$ P, |) ~6 O* T' y2 N
- $my_post['post_author'] = 1;! T1 y0 S* R0 D6 \! F
- $my_post['post_category'] = array($cate);; n/ |* Z& K' u% n9 x, p
- $my_post['tags_input'] = $tags;
+ y( b- m C/ Z- Q8 @7 z - //$my_post['tags_input'] = array('tag1', 'tag2');- e9 ], T9 D1 C0 ~, H
- //$my_post['post_status'] = 'future';
8 w2 [# L- n! ?1 o - ////$my_post['post_date'] = '2010-07-04 16:20:03';
/ k$ j8 R ? n# y: q
7 C. t1 O6 O" o+ S" a) F/ u- // Insert the post into the database
( e" @, x: ?. Q+ t7 c% U0 `5 y* M - $ret = wp_insert_post( $my_post );
/ c; N5 t" x1 Z. ` - echo $ret;
" a) e" X) u% I* e! b - ?>/ e& D2 m* |: w. Y/ W/ m9 K
复制代码 我自己写的- J G c6 z: n
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|