|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
/ n2 U" Z2 ^+ a* l1 _5 Y, e' H+ T4 R) w! v. b2 H
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持; T2 Z6 M) }4 [' U
1 R' x4 q% I/ A1 ^7 Z我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了, L: a4 i3 Q7 u' b. n
" D' r. x/ O; B, P7 }7 u
方便实用 简单 何乐而不用呢- 3 x$ @! \$ U, E; z$ J z) A
- <?php. O- N2 m( }, S2 Q* {3 U6 c6 q% y
- ' J, t' {$ Y2 m5 p
- define( 'ABSPATH', dirname(__FILE__) . '/' );
/ N' l8 W% {1 h7 i- w - require_once( ABSPATH . 'wp-config.php' );
8 {. N, k7 o7 d1 f) a% D, d - require_once( ABSPATH . 'wp-settings.php' );
* b. c% I$ X* V8 P' U; g, F - require_once( ABSPATH . 'wp-includes/class-wp.php' );
) q: f' d$ {; m - require_once( ABSPATH . 'wp-includes/functions.php' );0 D1 k4 d2 ?& O, [0 e& d& ]
- require_once( ABSPATH . 'wp-includes/plugin.php' );
5 n$ t0 z% Y8 X! |- J - $title = $_POST["title"];
/ j: B5 F0 r: x- e/ S/ F/ n - $content = $_POST["content"];/ j( {- P* u: [
- $tags = explode("_",$_POST["tags"]);
L7 j2 L" d3 I - $cate = $_POST["cate"];; F1 e. ?( e/ {+ q0 {' Y) Z+ T
- //print_r $tags; c5 q4 @! I) S% z. i
- //! Y3 s- r4 Q; l) y9 m* _
- //; I1 M, Z8 h1 N! J3 O f
- $wp = new WP();0 q2 b3 G, ]2 Q0 |
- $wp->main();
& f1 D( N( o' n1 m& U1 C( o+ k - /// m0 J& r. u1 l) l! c. Y! i3 F3 E
- $my_post = array();
- j2 |/ N S+ p+ B* D - $my_post['post_title'] = $title;+ P2 e4 Z) u% t% V" `6 h7 f: i2 P$ w8 p4 t
- $my_post['post_content'] = $content;: u) [4 ?8 E$ ?& Y
- $my_post['post_status'] = 'publish';# c0 B( v. p8 W
- $my_post['post_author'] = 1;/ U5 M, Z9 ~( Y& h" V
- $my_post['post_category'] = array($cate);
, e' k! \. k2 L/ y0 a - $my_post['tags_input'] = $tags;
* x9 C2 |" w% @$ m# y3 \% f, l - //$my_post['tags_input'] = array('tag1', 'tag2');
- I6 l) n, H$ o/ p' x& M - //$my_post['post_status'] = 'future';3 z& o& U! n) U- {
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
' J* C. U5 @4 u m - 5 N, y, B3 H8 _
- // Insert the post into the database
5 W! C0 `5 k# n+ i- | - $ret = wp_insert_post( $my_post );* e- I/ Y" t6 ~3 c* ]. ]
- echo $ret;$ {5 W) l m6 U' k1 U
- ?>7 f t. X9 ^. ]; i
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- & q' z: \0 S* R. v0 j- T8 b; M% }
- <?php
# p0 S8 ~% E& P+ S( T @' z2 F - define( 'ABSPATH', dirname(__FILE__) . '/' );+ u6 Z- Q9 q+ q; o4 J
- require_once( ABSPATH . 'wp-config.php' );; k) i& ~$ Q+ I$ q
- require_once( ABSPATH . 'wp-settings.php' );& f( `: E7 p& l7 v% i }
- require_once( ABSPATH . 'wp-includes/class-wp.php' );2 T: V( n' ^) L9 w: {
- require_once( ABSPATH . 'wp-includes/functions.php' );- s* z0 C4 G/ E
- require_once( ABSPATH . 'wp-includes/plugin.php' );
% h; |, a. d0 ` - $pic_name = $_POST["pic_name"];9 ]2 ]* Y/ U0 U+ ~! [
- $pic = $_POST["pic"];7 o$ n: [9 @9 a8 J
- if($pic != "" && $pic_name != "")6 L& K- o+ M1 x0 t; H$ e, p, e
- {
B5 @7 g. s* H1 [( L o - $path = "images/";6 [# \' R# R' [/ f X' C( Z; n6 ~
- $pic_name = $path.$pic_name;2 ~ x4 O" {+ `+ a. T
- echo $pic_name;
! a5 B5 N- a5 W* |3 ~8 f' o. Y - echo "||";8 \4 [2 a E, ?1 F+ X3 o3 Y
- error_reporting(0);) D( C( A" j8 J. v+ O+ M3 k. Q
- mkdir("images");3 ^4 a8 v1 n( H9 [! l/ w" b; O0 F# P- U
- $handle = fopen($pic_name, 'w');1 }9 V2 V1 ~5 g5 T4 \
- echo fwrite($handle,file_get_contents($pic));
' s4 n9 T/ g" @5 o; E - }
) n8 F$ S. A8 I7 y- r7 ` - ! q% G; N8 y) L P% ]5 u6 X" Y
- $title = $_POST["title"];0 O( j4 x( v8 m+ Q/ i. ^* W
- $content = $_POST["content"];$ f" [7 k- z O% p
- $tags = explode("_",$_POST["tags"]);
3 o4 K5 o+ W) _8 x: g$ I - $cate = $_POST["cate"];+ Q+ D" U: Q+ j
- //print_r $tags;
/ t$ [0 z! H* C6 r+ S( H) i - //
* q6 h) c( u& D! x2 | - //
7 k- _4 T7 a; E2 N0 ~+ g% L) b - $wp = new WP();2 c! E2 h% D# k3 N4 |
- $wp->main();
" c2 F3 j& q/ o - //
9 H( a) x9 h4 j7 b/ H - $my_post = array();: z* a% K) ]7 c7 B. B- L
- $my_post['post_title'] = $title;
2 ^/ Z N. N1 k1 d. C - $my_post['post_content'] = $content;# l' _8 {, s/ s) y0 ?' m
- $my_post['post_status'] = 'publish';9 M$ f! v1 C% p! t; X+ w. x6 V
- $my_post['post_author'] = 1;
1 r; d2 ~! \( Z; O* Z4 Y/ N+ O+ D- \ - $my_post['post_category'] = array($cate);0 d6 L" ?% N: h/ J) s" ~
- $my_post['tags_input'] = $tags;
9 d9 D/ x( {% R" s: i; T - //$my_post['tags_input'] = array('tag1', 'tag2');
6 x* x* B1 j3 h7 p3 @: S - //$my_post['post_status'] = 'future';
! s% c( E1 @2 F# @7 r - ////$my_post['post_date'] = '2010-07-04 16:20:03';
, R q8 [$ L% S0 C2 t. I
4 M6 G2 Y- `2 |. ]4 g1 x: x- // Insert the post into the database
- p7 z% C) I u1 X% |5 V7 { - $ret = wp_insert_post( $my_post );" v, u7 ^, C1 p9 f( G. W
- echo $ret;
9 [* c" x- X. a7 T- s( K - ?>
( K2 P- Y& v3 I# S" k
复制代码 我自己写的6 e# D+ T- `8 G# h
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|