|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
8 @7 M4 V5 }: d2 t
# D" g, @- W, g- f* \! Z* y' g直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
, c) G1 f$ u* w
/ J( J5 v. T- Z; k; C) b8 g我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
/ a+ v, h, }7 H& L8 C( q
2 i' b! t# e4 w7 v; g9 T方便实用 简单 何乐而不用呢
+ G8 E y7 b7 @. @. P% l- <?php# Y1 ]5 A( {& o, O" d, |+ ^
! x! u/ A1 I7 u1 n- define( 'ABSPATH', dirname(__FILE__) . '/' );
4 c6 z7 ^% L- P8 t, T - require_once( ABSPATH . 'wp-config.php' );! q6 y% z$ E/ m0 k/ |8 k3 ^1 d: W
- require_once( ABSPATH . 'wp-settings.php' );9 C, \3 x# C! J
- require_once( ABSPATH . 'wp-includes/class-wp.php' );& E# V) M. m2 |7 I
- require_once( ABSPATH . 'wp-includes/functions.php' );9 M5 M" G. ^4 ^+ N5 g
- require_once( ABSPATH . 'wp-includes/plugin.php' );
: J4 ^& J3 Y, O# R9 r" x$ m - $title = $_POST["title"];1 X* [+ H3 O8 j: D, u5 |
- $content = $_POST["content"];
# o; n7 g6 Z7 o% u% p, C - $tags = explode("_",$_POST["tags"]);
2 R U- G5 }+ I& f/ Z- w - $cate = $_POST["cate"];
: U2 k) e( |( f1 q - //print_r $tags;5 m/ M; r. a! l; M9 y
- //
, V$ r9 K- W) M5 Y - //' ?0 `" {, l# ]/ M H- W( L* E
- $wp = new WP();
3 r. O# {2 D! v* J+ Z7 S3 h% O - $wp->main();' b$ j! l. t \, J
- //
4 w9 Z/ `) f: u/ j9 m - $my_post = array();# T& P6 w1 w" P9 J
- $my_post['post_title'] = $title;
0 I9 K/ } g0 A" H3 j) r# _ - $my_post['post_content'] = $content;
5 [$ c9 L; _' e - $my_post['post_status'] = 'publish'; h5 q, y2 z2 u6 J0 E) p: G+ |
- $my_post['post_author'] = 1;6 h$ W& U/ d6 O# G9 R
- $my_post['post_category'] = array($cate);3 Q# l; _3 R- j5 Z
- $my_post['tags_input'] = $tags;
, T( O! d# U" h8 W! Z - //$my_post['tags_input'] = array('tag1', 'tag2');
( {0 }3 w5 _* a& H/ V1 L+ k - //$my_post['post_status'] = 'future';
8 F6 Y1 X* o9 [ - ////$my_post['post_date'] = '2010-07-04 16:20:03';
. H! G8 l3 o7 T) J; h - , n6 d9 ?4 A. P( _% j; _3 j% B: F
- // Insert the post into the database& X0 \* Y7 F4 X6 i- X& U
- $ret = wp_insert_post( $my_post );
4 S2 ~, C( e/ C/ Q - echo $ret;/ w3 U* i& f( @- ^$ a m
- ?>
9 F" A- {; M6 h4 a0 D- w
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
0 p2 }" R9 i, p& _. q& J& W- <?php: e+ }3 C& e* M( S, h" n# W
- define( 'ABSPATH', dirname(__FILE__) . '/' );
$ T b, ]/ D# P* \5 P' P1 q( x* ^9 Y - require_once( ABSPATH . 'wp-config.php' );
6 h: u3 X0 _& u- s4 [ - require_once( ABSPATH . 'wp-settings.php' );
( [) _9 w* `9 ]7 M - require_once( ABSPATH . 'wp-includes/class-wp.php' );
( H' y9 S( a, x0 W - require_once( ABSPATH . 'wp-includes/functions.php' );# U, }) R* a$ d" V b' d
- require_once( ABSPATH . 'wp-includes/plugin.php' );9 g3 q1 @: ?; x4 R5 ~2 n3 t
- $pic_name = $_POST["pic_name"];
6 l! ?; G7 ~9 S; l+ E0 A/ g - $pic = $_POST["pic"];. [' b/ U: ?( S) `; ~2 J
- if($pic != "" && $pic_name != "")$ y! o& z' G8 N! ]: N
- {
0 J& P0 x0 Q/ B; k5 E7 _2 t, O - $path = "images/";
3 t h1 `0 e! R( _ - $pic_name = $path.$pic_name;7 o6 h4 W( O/ P! O
- echo $pic_name;
7 M# q6 E) R5 p/ D; K - echo "||";4 @' J, h5 D9 d+ }
- error_reporting(0);' N" F2 e1 W( h1 T3 P' W2 p6 \$ b
- mkdir("images");
+ M$ {7 Z9 A1 t# ^4 O9 ?' ? - $handle = fopen($pic_name, 'w');0 Q6 ~+ W2 A1 E# `6 n% H
- echo fwrite($handle,file_get_contents($pic));9 N. b1 o! `; a c& g, J8 C( C
- }: o2 K, V, A8 ^: R
- 5 E! j0 r5 H3 Z- c: S8 }
- $title = $_POST["title"];
7 e! f+ K8 w- F; S* q4 j' G - $content = $_POST["content"];2 O% I$ { ^; N& I8 U
- $tags = explode("_",$_POST["tags"]);; K. {, @9 i" ^' s9 E. d. x
- $cate = $_POST["cate"];2 |' n: R* P+ y# e. |
- //print_r $tags;2 i$ L6 q7 k2 ^" w; `
- /// t- e" H; W8 V8 |) v
- //( m' {0 D, f2 Z; N& l G0 s: f6 J$ a
- $wp = new WP();
) X% H" {1 t) k. N- r% i: _ - $wp->main();$ l6 P3 {/ }5 K8 w, _" o
- //
: V& x" P' _ R - $my_post = array();
6 b/ V4 e) [' d9 R' B6 E$ g - $my_post['post_title'] = $title;
: P% A; ?1 N( w - $my_post['post_content'] = $content;7 u! z, S9 A# l* s6 _% L2 y u
- $my_post['post_status'] = 'publish';
* F& b! \ B9 X' E - $my_post['post_author'] = 1;
( {7 W+ k7 q: [7 [ X+ R - $my_post['post_category'] = array($cate);1 B _( q+ Y$ g' K9 q' M
- $my_post['tags_input'] = $tags;1 C6 B% {- {. Y( Z+ B5 G
- //$my_post['tags_input'] = array('tag1', 'tag2');4 l R. a6 {, s) Z
- //$my_post['post_status'] = 'future';
# H1 U" \& v) D9 I8 E% h' Y2 L - ////$my_post['post_date'] = '2010-07-04 16:20:03';
2 X m6 e5 v" s/ w8 n& G4 _3 ?) V - ' @3 {( Z7 Y: }- \2 q- n; O; O
- // Insert the post into the database
. R) T* u- d0 f* l5 `7 }% Z. D8 M - $ret = wp_insert_post( $my_post );) p) G# R% l( U$ f
- echo $ret;
8 T& e% B' U; C4 h V+ Q- C - ?>( | z; \ ~4 e8 a# Q
复制代码 我自己写的' v% z% {% s2 {0 T9 `/ `9 u3 x
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|