|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
; f7 l1 V; V7 \' B# ]3 y! W( N) O) D& ?( M# S
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
+ L' d4 \% r' V6 c+ E6 z/ ] y/ R* J
+ Y+ @1 O% Y) G# c4 i" ]: y" ]我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了, I/ O, y" p' k( z" }: G
' g3 X( L7 `- ^# A$ q8 c方便实用 简单 何乐而不用呢
* C0 G. h) |3 y3 a# w- <?php& P$ k1 L1 K8 E* [( y
- + z# K( U- W% U+ T, S
- define( 'ABSPATH', dirname(__FILE__) . '/' );; o5 P# M0 u, ^! n' E1 D
- require_once( ABSPATH . 'wp-config.php' );
3 V8 l. @4 _; ^% }. H3 r - require_once( ABSPATH . 'wp-settings.php' );
6 s0 M6 C0 O+ l2 i& z/ w( h - require_once( ABSPATH . 'wp-includes/class-wp.php' );
8 [# \- u2 A) P$ |; i% J' }. y - require_once( ABSPATH . 'wp-includes/functions.php' );
+ k) {7 z0 X a: a - require_once( ABSPATH . 'wp-includes/plugin.php' );/ L& o; C' x/ z" j1 C& i
- $title = $_POST["title"];4 D( _. ?8 e7 z: |2 Z) D9 i1 P
- $content = $_POST["content"];
& p' H, t E# ^ - $tags = explode("_",$_POST["tags"]);# u4 f9 |9 m/ Y, O
- $cate = $_POST["cate"]; ~+ ]9 l5 [+ N) S
- //print_r $tags;
$ f4 u, s" x* N/ I7 q+ s - //9 M4 K5 E0 I1 _$ p7 F4 l
- //! L) ?: q8 D* b4 q/ V; b
- $wp = new WP();! H8 r* m* r/ Y* c, V: Q7 }) |+ ]
- $wp->main();" K( f- u. F8 Q& Z, u2 P- [9 j2 T
- //# ~% Z, X. ]" U% @/ k" @2 D2 l( {. h
- $my_post = array();
5 ]1 L$ x# }5 I5 L - $my_post['post_title'] = $title;
% F- l4 v; H: Q: X' d3 G4 q; n - $my_post['post_content'] = $content;- _+ D- `* S: g0 }. D
- $my_post['post_status'] = 'publish';0 d2 n( R0 d8 b7 Y9 E
- $my_post['post_author'] = 1;0 {7 s# g# ^% x$ v6 j$ |
- $my_post['post_category'] = array($cate);$ l- H$ G. r) B* U; W- ~8 N' f; Z
- $my_post['tags_input'] = $tags;
7 m: E; l% X6 C - //$my_post['tags_input'] = array('tag1', 'tag2');- Q1 K" H- e$ M Y* a) C
- //$my_post['post_status'] = 'future';% k$ f3 G9 `4 d2 v
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
: v: o3 e* l3 W% W) S1 r& t - ! }& o( H1 P3 J. y% S
- // Insert the post into the database
5 [0 j6 j. L1 g - $ret = wp_insert_post( $my_post );
- _ x: J" Q4 @/ W: B( \4 R; A, } - echo $ret;
1 U$ q+ ~" {- o2 b( u4 V" ?- L - ?>2 E2 O7 S# a1 V
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
8 d0 I8 k5 B( z- h* H3 \7 E- <?php: k0 o) ]0 ^6 \8 } a
- define( 'ABSPATH', dirname(__FILE__) . '/' );5 ?! j8 ~, s' ?) y9 L0 t
- require_once( ABSPATH . 'wp-config.php' );) {7 N4 V8 @5 u( U, S9 ^
- require_once( ABSPATH . 'wp-settings.php' ); M* \2 p' S* w) L' a
- require_once( ABSPATH . 'wp-includes/class-wp.php' );/ ]( Z e- ^9 n4 g6 z; T
- require_once( ABSPATH . 'wp-includes/functions.php' );' H$ ]0 ^) J4 s. Y' r: d2 w* J: I
- require_once( ABSPATH . 'wp-includes/plugin.php' );- }. F4 }7 x- t; @
- $pic_name = $_POST["pic_name"];8 m/ X* g3 P' ~" Z5 [5 {
- $pic = $_POST["pic"];2 s& F3 y( @$ }- c( L, g0 I: b
- if($pic != "" && $pic_name != "")9 U3 s2 `8 o( ]
- {0 q n/ a$ V) l
- $path = "images/";& u( j ?+ X6 {+ x' G( [
- $pic_name = $path.$pic_name;2 R: `9 t$ Z; t* L6 f4 I2 c, T5 }
- echo $pic_name;
' A" {2 S# l) [' Q2 B+ g - echo "||";
- x& p4 L* A& g! ]' m) Q6 K - error_reporting(0);7 P$ B6 c" \& c @* J$ i
- mkdir("images");
+ _ @: ?( }+ Y. ^6 z6 A - $handle = fopen($pic_name, 'w');
w, B$ @( g! |. ^6 B% Y - echo fwrite($handle,file_get_contents($pic));
A" x8 r. Z+ W) K9 u - }
+ N6 U6 R1 i- J6 } - + `% ?. ?1 f& n' g. n v$ |/ z
- $title = $_POST["title"];
- ^# K0 e b. B* W4 ^# Z5 g - $content = $_POST["content"];! z9 w B# h* z" x3 }
- $tags = explode("_",$_POST["tags"]);: |. V2 o+ r5 V1 T
- $cate = $_POST["cate"];$ l0 d1 m# ~1 y1 d$ t* p
- //print_r $tags;1 f8 m. q5 _: q& \ `5 D# C
- //. b& {* K) c" _8 B/ v0 _
- //5 @# j L/ P! h; Q: d1 O' Z; c
- $wp = new WP();$ w9 ~* W) |' G# H$ p" b
- $wp->main();
1 i3 \/ D0 d8 f. _% @ - //
) J _0 r6 A( v- j7 k6 R - $my_post = array();
: i% B9 R) w, t - $my_post['post_title'] = $title;. o5 k, \, g3 d% ^
- $my_post['post_content'] = $content;" j* ~9 F* M3 n6 V( t
- $my_post['post_status'] = 'publish';1 F% ]! S3 _( G9 [
- $my_post['post_author'] = 1;9 T% |: b# L1 E' v
- $my_post['post_category'] = array($cate);+ ?! {# o& z ~* Q
- $my_post['tags_input'] = $tags;
( a* O/ _2 H0 O& l1 M9 d - //$my_post['tags_input'] = array('tag1', 'tag2');
) w2 m. P6 ]3 P5 c - //$my_post['post_status'] = 'future';* J* }3 i8 w; \ Y, [
- ////$my_post['post_date'] = '2010-07-04 16:20:03';6 b0 ?! k2 l" D$ u
- 4 P9 H( ]; {) G B
- // Insert the post into the database4 s6 e1 b" y. p+ r* S! Z/ O5 m7 v
- $ret = wp_insert_post( $my_post );
% q# K: p. d$ P5 Y* v - echo $ret;* ~1 y) n. g/ j4 p4 Y" D2 K l
- ?>. G+ N. E, u& [1 s# K
复制代码 我自己写的* m1 f s5 V0 X# H! y# m/ K8 e
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|