|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
' Q0 d( b( a# W6 l
$ ~( @2 u$ o! ?/ T直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持' H& V' J4 [" z/ N9 g* V
8 I& ^* O9 _/ {6 N
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
6 w6 E. t: i% R% G$ k
* h% n; Q+ L. h" Q7 _方便实用 简单 何乐而不用呢- + b/ p0 F5 u. O8 F5 @
- <?php4 E8 E) S+ X$ d9 ~* W: x; r: h
- * t5 ^( S0 ~8 q! s# r) \) X
- define( 'ABSPATH', dirname(__FILE__) . '/' );
\9 X2 K% B5 O# z9 L - require_once( ABSPATH . 'wp-config.php' );
: o9 D3 y# `/ x$ M5 d - require_once( ABSPATH . 'wp-settings.php' );
3 F- `$ D# k! P5 W w - require_once( ABSPATH . 'wp-includes/class-wp.php' );' i* C! Y( z/ k4 ]* [- v$ Z
- require_once( ABSPATH . 'wp-includes/functions.php' );9 F9 f) g4 @9 C4 a
- require_once( ABSPATH . 'wp-includes/plugin.php' );3 p, `! K5 O! |4 o! b" W* `
- $title = $_POST["title"];3 T+ T; h1 B( ?8 l7 `
- $content = $_POST["content"];
. d/ b; q0 S7 [* h6 a - $tags = explode("_",$_POST["tags"]);
1 ^ l8 E6 {/ K3 U P7 T+ a" ` - $cate = $_POST["cate"];
+ P/ }. c' d4 x' F; _+ m - //print_r $tags;1 r) G5 R9 F' N6 a% N5 J
- //
1 Z5 s7 c# ~) y3 |* c7 [$ I+ H - //+ W/ _# z$ D6 F0 d' J
- $wp = new WP();
1 I: U7 L7 _, ]' ^3 e) \ ?6 | - $wp->main();4 |1 k& t/ Q. O* A# f) }7 ^
- //2 _* t9 q( m! s8 T
- $my_post = array();. f! J1 {2 p0 Z
- $my_post['post_title'] = $title;
+ b( d1 Q8 T( [ - $my_post['post_content'] = $content;
% r; L: H1 _( ^8 i/ S3 n- F - $my_post['post_status'] = 'publish';
# C! _3 a% o3 j0 G) N, ` - $my_post['post_author'] = 1;
. d) v& g8 _3 h' w% B% q - $my_post['post_category'] = array($cate);
0 n3 s6 w, y. j/ w( }- ` - $my_post['tags_input'] = $tags;
3 u- i3 ~6 B) e% P V. g - //$my_post['tags_input'] = array('tag1', 'tag2');
0 M2 U" ?8 r' r! P5 _& v - //$my_post['post_status'] = 'future';
9 O9 f n' Z7 C0 X7 b7 Z - ////$my_post['post_date'] = '2010-07-04 16:20:03';
( A9 z8 O3 k: [) ]
( {. t9 |9 o" I s( |- L- // Insert the post into the database
# p/ r! x5 z$ M$ H) y - $ret = wp_insert_post( $my_post );
, M. J% G; Q( j. D- ] - echo $ret;$ a5 ]8 I L X- Z" q3 C7 Z
- ?>
2 @3 G+ o7 K* F. o) W/ H
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- # D* S# @, Q! n: U
- <?php+ a$ z' E4 _+ ]% S4 J" q1 ]
- define( 'ABSPATH', dirname(__FILE__) . '/' );
: n# M( c# `* @7 ^. `/ @ - require_once( ABSPATH . 'wp-config.php' );
9 @0 o3 J d/ ^ - require_once( ABSPATH . 'wp-settings.php' );; r& U* ^; b& @5 i( p% M' F6 N
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
& p l: T, O! `3 R% l - require_once( ABSPATH . 'wp-includes/functions.php' );
3 P9 p& u0 m1 L; \6 S/ m - require_once( ABSPATH . 'wp-includes/plugin.php' );" N& c2 ?* V6 H9 E8 ?
- $pic_name = $_POST["pic_name"];8 p. N1 l0 W5 q+ A
- $pic = $_POST["pic"];
' L7 P* h+ m$ M, @ M! @1 s7 l: P+ s) { - if($pic != "" && $pic_name != "")
0 U! }$ q d/ e. P. O - {
$ M. L7 z/ b) k" Z% ^ - $path = "images/";
, j9 Z/ R/ J7 W3 E7 W( e - $pic_name = $path.$pic_name;
$ R. O1 s0 @0 }4 @1 z - echo $pic_name;
}! F( _& w& g$ w5 v- U) V4 L6 I; n - echo "||";/ W1 Y& ?" n* x- k! u" l) r
- error_reporting(0);6 Z' f$ e! L4 t; |( m
- mkdir("images");* k7 w- C0 x+ w: B( d
- $handle = fopen($pic_name, 'w');
; Q3 ^* S! Z0 m - echo fwrite($handle,file_get_contents($pic));
+ G. Y! ~; s) O/ K/ D$ J - }
5 X% s* D: W5 _- a
; n; L" n: u& I- $title = $_POST["title"];! T& P/ [: T' r8 g2 N/ G
- $content = $_POST["content"];
# T1 j+ j4 m6 } - $tags = explode("_",$_POST["tags"]);
9 K& x$ d) s, j# z. m6 d% L - $cate = $_POST["cate"];
" ^( C" n! c U* V: p9 @: h* ^( Z - //print_r $tags;
1 T) d# s! k' o! X/ |; A. u3 ^9 y1 x - //
, e" V& D+ o k2 f3 H - //
( e j& ]& C1 ^ E' l5 C/ x( O - $wp = new WP();( V2 C0 F. ^: Z9 C1 I' l
- $wp->main();
7 D2 a) n) z- \ - //; d% y$ t& B: j
- $my_post = array();
( O, c4 ` @. `) q! g; X( d* ^ - $my_post['post_title'] = $title;
; W! ^& C7 A! g( d* m$ i3 x/ K' l3 G - $my_post['post_content'] = $content;
4 E! s* P0 c# f4 B - $my_post['post_status'] = 'publish';
. d! q, P- M9 r% D f6 q9 D! U - $my_post['post_author'] = 1;
" a) ~: A @4 D# F+ m - $my_post['post_category'] = array($cate);
- B4 P$ ~& s/ b! f - $my_post['tags_input'] = $tags;
7 e; K5 x8 G, _0 a - //$my_post['tags_input'] = array('tag1', 'tag2');
3 ]5 E% Y; [8 i - //$my_post['post_status'] = 'future';: B+ ?1 c% w3 I
- ////$my_post['post_date'] = '2010-07-04 16:20:03';1 M6 _* z0 n. k o) l! V
- 4 [& y9 G& O! A6 D1 n; k# H- b* z
- // Insert the post into the database
/ \7 c; C4 h+ o$ r" Q ^$ R - $ret = wp_insert_post( $my_post );
# t Q: i A( O7 S( y - echo $ret;
4 n/ K7 E; N# Y9 X9 I9 C- D. S - ?>: r5 W' ?1 v8 y' B$ P; p# X8 x
复制代码 我自己写的: V, Q0 W4 k% z6 ]/ ^0 |
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|