|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 " _( Q- O. |/ ?5 j B0 W
8 l; U5 E9 G6 c& q/ S3 Z# ?9 m) }
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持. O7 L1 G) U4 a) L% Q$ u0 S
2 [+ d* G* h( A- o. s我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
6 z- ^+ L! n9 V6 c' H |+ }& {: W$ F0 @; v# G( u ` y
方便实用 简单 何乐而不用呢
; W( G7 F. }# u: F/ `* P- <?php" A4 B; B, l# _& D% m: u) J# ~
+ j: V, \; Q9 o6 b- define( 'ABSPATH', dirname(__FILE__) . '/' );8 s# E3 I% P+ B' [# s/ u
- require_once( ABSPATH . 'wp-config.php' );
. }# S6 x0 t. J1 [( r x - require_once( ABSPATH . 'wp-settings.php' );
[! K& O) v, E! h( n - require_once( ABSPATH . 'wp-includes/class-wp.php' );' p3 B* i4 b1 i, x2 T! _
- require_once( ABSPATH . 'wp-includes/functions.php' );
/ ?2 l; s1 s; Q! y6 ^5 z - require_once( ABSPATH . 'wp-includes/plugin.php' ); B, Q. N' r- W$ M2 Y
- $title = $_POST["title"];
+ a* x! u5 A* ^ - $content = $_POST["content"];
/ N# Z# E$ S1 {+ g; N - $tags = explode("_",$_POST["tags"]);1 b5 W7 P; y* M/ c1 A) Z6 @$ m
- $cate = $_POST["cate"];$ _4 h# B; u/ b6 }2 x" B
- //print_r $tags; I$ I; d2 F/ e* D3 S4 k
- //; [; m$ y/ Z6 i8 o5 ?8 K/ K4 _5 L
- //) W) w+ z4 `% d
- $wp = new WP();
7 q% ~7 @# y9 B! Q0 `. W - $wp->main();
; Z( X3 x: ?) I+ V - //
2 w- z7 F# `' V! x' ` - $my_post = array();5 h" ]- v- u0 E( v3 Z5 p
- $my_post['post_title'] = $title;
1 x" j& a# g* ^0 L - $my_post['post_content'] = $content;
4 @& f5 D- t+ i/ \" ` - $my_post['post_status'] = 'publish';
6 L& [2 Q1 q/ |! Q, E/ D* c - $my_post['post_author'] = 1;7 `/ ?; R1 T9 k7 ^
- $my_post['post_category'] = array($cate);+ q& z* A: S( k3 s* @ [; ^
- $my_post['tags_input'] = $tags;
6 C: z1 H0 h$ v& g V6 ]" [; ` - //$my_post['tags_input'] = array('tag1', 'tag2');
/ s$ p& H/ h S) C: h2 z$ n - //$my_post['post_status'] = 'future';. z( _& G, U1 Z! l" R
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
; ]9 U P( b4 z - 2 K' m5 q. n: v
- // Insert the post into the database
/ P! l7 b4 k" o+ _; V* x6 ~ - $ret = wp_insert_post( $my_post );
- `1 a7 ^1 B1 W* } - echo $ret;) l; h9 W; L5 l$ f9 I- p: {4 t
- ?>& K7 {8 b$ ^ }5 P- C
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 7 j4 y; o1 r# z; Q
- <?php$ K" Z' N0 [2 T% K- ^
- define( 'ABSPATH', dirname(__FILE__) . '/' );& r4 `# ? i- i
- require_once( ABSPATH . 'wp-config.php' );
! z/ B/ }# o" l% [" l* D - require_once( ABSPATH . 'wp-settings.php' );2 x2 a; |. g* w s" D* O7 b
- require_once( ABSPATH . 'wp-includes/class-wp.php' );9 O( C4 N, C+ L8 s# p" S
- require_once( ABSPATH . 'wp-includes/functions.php' );+ K. e: i! ?) d' b4 ~/ [! q4 c
- require_once( ABSPATH . 'wp-includes/plugin.php' );
) A" f+ S3 O. y. L: }7 g - $pic_name = $_POST["pic_name"];0 T. [, ^7 @, k$ r8 k* x6 v
- $pic = $_POST["pic"];% u* w$ Z. x6 ?" f* o
- if($pic != "" && $pic_name != "")1 H) g- V. h2 g& C: |& j T# p
- {
+ a4 C- W; [% Z1 ]- r: a - $path = "images/";8 f* C e5 x! U9 G, n
- $pic_name = $path.$pic_name;4 \+ J/ G& g8 V- A( t. v
- echo $pic_name;
# |* l6 o: p' G3 ]/ }6 H - echo "||";
! b) r0 h0 U! R: B$ r3 s - error_reporting(0);/ p! c' h3 I5 i& K% K! G
- mkdir("images");7 i; `0 _" R& V$ L7 f/ [; \/ h
- $handle = fopen($pic_name, 'w');
@2 w8 K( u2 j/ K9 a - echo fwrite($handle,file_get_contents($pic));
! H3 {6 N% l5 J- Z- c* I7 x7 B - }- X# U8 T" f8 |' Z
- ) I, Q5 E0 C8 Q9 C ~6 R
- $title = $_POST["title"];
$ Y! z+ @# g5 c) S- D1 K - $content = $_POST["content"];
/ T$ D, f/ W3 u2 m4 A$ A - $tags = explode("_",$_POST["tags"]);+ s# N8 s5 [) p
- $cate = $_POST["cate"];
: ^# | A) A$ I! j& G2 ]) V1 ^" [ - //print_r $tags;
2 [( P2 N* j9 B. k, c - //8 f$ U& \% T* {- v
- //2 C$ E3 P2 q3 ?6 J
- $wp = new WP();( F1 p A: }0 e: a! s
- $wp->main();
: H: N) b# }) P6 B' ^0 _ - //
; j. h$ ^5 `$ O# w5 b! P: K0 q+ b - $my_post = array();
/ k* L, f. I6 j i- R$ L. H - $my_post['post_title'] = $title;8 |8 H/ I( M* d w; r2 F6 e
- $my_post['post_content'] = $content;( a( k4 m4 s7 h" c) r/ J
- $my_post['post_status'] = 'publish';
8 s8 y7 n9 M# F& K" @ - $my_post['post_author'] = 1;2 ~4 |( w9 r$ I- v
- $my_post['post_category'] = array($cate);
7 V) @) A( `6 p& n/ [: r* g - $my_post['tags_input'] = $tags;. J4 x$ m7 _7 g' ?' Y7 v
- //$my_post['tags_input'] = array('tag1', 'tag2');
. I3 E7 `; _( F) g% h4 C5 }0 X - //$my_post['post_status'] = 'future';
% u# T/ p. Y4 }0 _) ~5 W2 o - ////$my_post['post_date'] = '2010-07-04 16:20:03';: _+ j! Q: I4 o. \, T" H! t
- 0 V* R/ M$ b. | S" v5 c
- // Insert the post into the database
) j4 Q* o" b/ r' G - $ret = wp_insert_post( $my_post );+ f. T/ e" r) G" p% C9 y
- echo $ret;
: R' ?! D4 B+ ?+ @# I& h - ?>
" I$ ]3 L( d5 x3 Z" D
复制代码 我自己写的; p& n1 D# B9 i% N/ `
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|