|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 4 t) x3 [/ l6 B J
* r P U7 g0 R2 a/ L' \4 G" R直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
# ?5 h6 Q" V0 o9 R. r
- l& e6 E# Z0 O6 M我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
8 _5 k" j/ L, c3 p
f$ E3 q+ P! L方便实用 简单 何乐而不用呢
; W' I/ | e% a: h- <?php
8 _) t- b$ D; d# W. j4 x' p - K5 w" k+ m" d* x3 y/ o+ `
- define( 'ABSPATH', dirname(__FILE__) . '/' );8 o# R3 x( i% W
- require_once( ABSPATH . 'wp-config.php' );; M) R- F$ j! n5 I \: e+ s3 b) d1 T
- require_once( ABSPATH . 'wp-settings.php' );: Q5 g! ^0 O) T$ T' E
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
- i$ S' d) z4 ^2 w! K2 B; v - require_once( ABSPATH . 'wp-includes/functions.php' );
( p, q* u$ V! f - require_once( ABSPATH . 'wp-includes/plugin.php' );; I ]4 r5 v# ~7 g- ^" U
- $title = $_POST["title"];3 f- P' C6 X; [1 u6 A, n& S
- $content = $_POST["content"];' T6 W/ }/ q3 e
- $tags = explode("_",$_POST["tags"]);7 P+ ^; t0 F0 [. ]
- $cate = $_POST["cate"];6 t0 B6 }+ x$ s& u
- //print_r $tags;' W7 [) \9 c: q( w
- //# H3 b! i( b! @- c' y! R
- //
$ p+ y- n' P- z7 k& Q* K3 h - $wp = new WP(); m! M) ]- f, V, I6 r
- $wp->main();
/ g0 v% K, Y' ]( ^6 `0 ` - //( }- m! }7 z7 a( U! q2 A
- $my_post = array();
' f3 c; }& o5 S( I3 |/ Q: V5 A - $my_post['post_title'] = $title;
' R6 l$ C1 [# k9 m% P. a) p - $my_post['post_content'] = $content;
9 e4 [, u# k) [" Q7 b6 Y - $my_post['post_status'] = 'publish';$ _) B3 v2 W2 V" S
- $my_post['post_author'] = 1;
9 _( B, c6 T' ~: | - $my_post['post_category'] = array($cate);% b0 T" n" |5 l' |' d
- $my_post['tags_input'] = $tags;
0 T, p( q0 X9 h6 ~7 g - //$my_post['tags_input'] = array('tag1', 'tag2'); I2 a7 e. a, l- P+ U- s7 C# t
- //$my_post['post_status'] = 'future';, q$ [! h# }( ~- }6 k" F
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
9 _- Z: a4 l; Y& W1 W9 r7 ? - 2 g% k/ L/ s. ~ J1 U6 n3 \
- // Insert the post into the database
$ `- L5 k! s- N8 D% i( {; F2 [ - $ret = wp_insert_post( $my_post );: c2 g. l: i; V6 c
- echo $ret;8 w% ]: x8 }2 O" o8 L/ ?
- ?>
7 y/ ]: {, B( @
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
. r% V @, S0 ? L7 d0 z) a- <?php
) }9 R6 B# b; D4 i2 L6 J K - define( 'ABSPATH', dirname(__FILE__) . '/' );- B$ b$ Z9 e. J1 z- {. M6 }
- require_once( ABSPATH . 'wp-config.php' );9 V: h: s7 F* \3 L! j$ o. }
- require_once( ABSPATH . 'wp-settings.php' );
# a& ?9 c1 i( }* v/ U - require_once( ABSPATH . 'wp-includes/class-wp.php' );
- p! t- F4 y9 T+ q - require_once( ABSPATH . 'wp-includes/functions.php' );
+ }- T7 {" {/ |2 ^# ?/ ^ - require_once( ABSPATH . 'wp-includes/plugin.php' );, ^+ W: n* a _* }+ ^) F2 [
- $pic_name = $_POST["pic_name"];
4 c7 B9 b* b( }1 ?3 {7 G7 K& |% L' Y - $pic = $_POST["pic"];
) ~ X0 i3 y+ {' ]4 D+ k! Y b/ X# r - if($pic != "" && $pic_name != "")
1 J' P" d/ J2 e. M' Q# }" m a- G: Q2 \ - {) L w! w; t9 F2 `0 a$ ?+ @
- $path = "images/";
3 x% n" L9 x/ g; M8 v2 L - $pic_name = $path.$pic_name;
$ M7 i* S R9 u7 K5 K8 p1 Q7 E - echo $pic_name;
( _7 Q; u! M2 ^: C! K - echo "||";; U) H; t" M* x! d3 z; G$ y$ X! B
- error_reporting(0);/ ?9 e/ Z( X# I. Z5 r1 |
- mkdir("images");
, |' p# U8 F2 } - $handle = fopen($pic_name, 'w');, ]+ o* k& C- S4 i$ L- E7 S* n
- echo fwrite($handle,file_get_contents($pic));2 t& i: T/ ^$ Z) @ h
- }1 z0 `3 I1 f* J$ \( `* F
- }; k9 ?0 u+ ~3 I- S% d6 M5 _! D- $title = $_POST["title"];
\% i& Y+ s+ H/ t- y9 p- J. l - $content = $_POST["content"];. R3 [: f; Q1 K
- $tags = explode("_",$_POST["tags"]);3 B+ ]( \! i' [. a
- $cate = $_POST["cate"];
! ] \# e$ j7 o" I - //print_r $tags;
: J: }+ w4 E# ]7 ` - //
; y0 H5 \' e3 u/ m A - //
+ v2 X Y- | B - $wp = new WP();
7 J3 ~0 D7 r: r0 I - $wp->main(); M0 g2 c$ |9 `! {4 e3 M
- //
0 d# ~/ o, C: B9 P5 I; q, I - $my_post = array();( f) H' b( V+ b
- $my_post['post_title'] = $title;
) S/ G5 c( m2 ~& J$ z+ n0 u - $my_post['post_content'] = $content;9 H6 C V9 y0 c- q% z% A" B
- $my_post['post_status'] = 'publish';0 y% q" v, y7 Y: `4 B A
- $my_post['post_author'] = 1;# W% o0 Y( t& j
- $my_post['post_category'] = array($cate);
& p* h" Q0 \- a. [4 c7 M0 k - $my_post['tags_input'] = $tags;4 g/ N9 J" e6 Y1 E; j& L
- //$my_post['tags_input'] = array('tag1', 'tag2');
. y; ?8 Q% ]5 a% B - //$my_post['post_status'] = 'future';+ o" q( W( C1 u V2 Y: l
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
, V" A) i) L, }; j
- y1 n- |9 A( [1 N* n/ o- // Insert the post into the database @7 p+ J! \) W. H3 l9 A8 ?
- $ret = wp_insert_post( $my_post );( ~' B8 V1 T9 p+ e8 L
- echo $ret;. z) s8 {& D' i0 o
- ?>
/ s! W% t8 I; l- m/ C( I- I+ h
复制代码 我自己写的
: t q4 ^/ I% C* [$ B) I' f插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|