|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 2 Z( u: @, F+ [ c. \; @9 p
' w1 X& H5 r7 O3 ~$ w, R
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
3 j+ }& q ?% A5 Y, g: Y
2 ~/ g$ q/ E2 e8 a% O我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了6 O8 K1 C C+ f
8 v0 T* D: W6 T/ e; p& b/ L方便实用 简单 何乐而不用呢
2 n$ S4 H. _8 P+ M$ w7 ?2 E- <?php
8 J! V6 Z8 m' R
* D( z7 \- d( I4 v( M! O$ |- define( 'ABSPATH', dirname(__FILE__) . '/' );. P \$ U$ `2 K( x
- require_once( ABSPATH . 'wp-config.php' );
5 u. |( l/ X4 t( w5 } - require_once( ABSPATH . 'wp-settings.php' );
0 O3 E; x( ?' \# p - require_once( ABSPATH . 'wp-includes/class-wp.php' );7 J: H$ [: N1 _: H
- require_once( ABSPATH . 'wp-includes/functions.php' );
/ z7 U6 S) o4 X0 l) |) s) F( _* | - require_once( ABSPATH . 'wp-includes/plugin.php' );
5 A+ V! U) p @3 V- { - $title = $_POST["title"];/ z- G$ G/ H8 F5 e: Z# _7 g4 x
- $content = $_POST["content"];# r) y* \6 n6 N, ~6 t: R4 c
- $tags = explode("_",$_POST["tags"]);2 c0 ^5 i' c5 m( E# Z; n
- $cate = $_POST["cate"];
% \3 [4 @0 O0 Y% \ - //print_r $tags;
2 e1 l" r. D9 [ - //9 D i' V, a& Z; C. A- Z
- //+ @( o5 R% G1 \7 a. a" n
- $wp = new WP();) u2 |; b2 _+ S: X! N* Z) L
- $wp->main();7 Z q3 B, {3 g4 Q9 G# y9 _
- //
3 P; k" _: y% ?7 v' F# h9 Q - $my_post = array();6 D9 L- g# @* z5 c9 P- \; n8 C
- $my_post['post_title'] = $title;
8 N# O8 T+ O2 ]' @2 [( Q9 C- u7 T - $my_post['post_content'] = $content;7 H4 S' U5 ?) q1 N
- $my_post['post_status'] = 'publish';0 N8 l( |- R: p' s& n- p# _, K
- $my_post['post_author'] = 1;( i# e! ]+ v. [4 S! c V- M) P G5 J
- $my_post['post_category'] = array($cate);2 U% C5 W* H5 c5 [3 o( h
- $my_post['tags_input'] = $tags;( {+ w" b: W0 B% R" D
- //$my_post['tags_input'] = array('tag1', 'tag2');5 i N' A+ \7 h/ R/ K; A
- //$my_post['post_status'] = 'future';- Q! i9 c3 S3 y& L* [/ w7 _
- ////$my_post['post_date'] = '2010-07-04 16:20:03';- M1 u* D! `: q0 \1 R6 O$ v ~
- - I" l, L6 A" v; y! I
- // Insert the post into the database
$ Y4 f/ h0 ?- }" v+ j8 F( s3 Y - $ret = wp_insert_post( $my_post );
" S6 z1 d3 ]0 F* y2 y0 L - echo $ret;
4 W5 r- E5 |! ]( K! \) k - ?>! ^7 h2 ]7 Y9 E1 w& P% ~+ ]
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ! o5 N) ], W# `. ^. b! h# i
- <?php
3 O7 O* R" y# i/ b6 G - define( 'ABSPATH', dirname(__FILE__) . '/' );2 S: z7 r9 F& Y" W/ y+ m
- require_once( ABSPATH . 'wp-config.php' );9 Y: a4 }. F: E! F |% |
- require_once( ABSPATH . 'wp-settings.php' );
" |5 E5 I% p2 F/ n$ i3 ~- W+ M% E - require_once( ABSPATH . 'wp-includes/class-wp.php' );
3 K, K2 v$ c9 S$ i. {0 r - require_once( ABSPATH . 'wp-includes/functions.php' );( r3 `* w# V2 b1 e! b) B
- require_once( ABSPATH . 'wp-includes/plugin.php' );
# ` r5 Y" X, A - $pic_name = $_POST["pic_name"];8 V: }$ ]* O* m5 b
- $pic = $_POST["pic"];
1 @+ _2 \6 G/ O9 i# A+ l. D9 g - if($pic != "" && $pic_name != "")
+ n& b6 U4 r! E K4 E9 _ - {
& R% B' ~8 X# H+ D - $path = "images/";
8 P. [. N; W/ p - $pic_name = $path.$pic_name;
3 ]% Z$ P+ `, M0 |2 q2 e8 U7 E - echo $pic_name;
9 f( y" q6 R9 O7 C - echo "||";: Q7 q" L# M1 j, r
- error_reporting(0);' N* k9 Y! v$ S; z
- mkdir("images");/ I$ I& j+ N5 P' A% `
- $handle = fopen($pic_name, 'w');
& S* Z( n% b( H: g* P& I - echo fwrite($handle,file_get_contents($pic));. x/ W9 |0 g( A4 E/ c( L
- }
+ E" I2 l9 Y7 ] G, t
1 Z E4 |' r9 {# P. y4 \) S- $title = $_POST["title"];
* B" B6 R$ l& z - $content = $_POST["content"];
* P4 ?1 i4 c5 r' D' n! o - $tags = explode("_",$_POST["tags"]);
& c6 r% f' P" W. \ N: }8 z - $cate = $_POST["cate"]; [6 b* |5 p% E3 x
- //print_r $tags;) }$ @4 a7 w7 z$ X! o
- //
, e1 L% M+ d( k" A% ?7 [ - //, Y$ S2 }: `3 H" P
- $wp = new WP();
( R \$ D; z/ Y - $wp->main();
2 w! }) `, ]8 R - //
! H" {5 _7 o) S - $my_post = array();$ n8 [* S) E0 G" r# s, h) L c
- $my_post['post_title'] = $title;
2 m9 {% X5 s# F; R* [ - $my_post['post_content'] = $content;
1 b' ?' n# F7 \0 E4 \ - $my_post['post_status'] = 'publish';
7 h' r% s, m4 N3 j) D - $my_post['post_author'] = 1;
" W9 w6 i* E! k, ^ - $my_post['post_category'] = array($cate);9 t+ e2 n* x& b" c) ~% M
- $my_post['tags_input'] = $tags;9 G) R+ z+ M: }4 M9 _- N: q
- //$my_post['tags_input'] = array('tag1', 'tag2');* y5 m1 F q. S% y. ^
- //$my_post['post_status'] = 'future';
- }0 m" w" ^; n1 ~7 a* _" K - ////$my_post['post_date'] = '2010-07-04 16:20:03';
9 [/ b' m. L- Y2 I/ m2 c
! r% N/ j: \+ h% Q [6 F" F9 O- // Insert the post into the database0 C G. M$ ]# E/ U* N
- $ret = wp_insert_post( $my_post );
' `( i% o& S0 f1 q& ]6 {8 h. o- o - echo $ret;5 e& g- t! i0 n* r9 B7 o% @. N; b
- ?>0 W/ T( K( f, n0 m. v' L7 [
复制代码 我自己写的
' Y. p% @$ b, ^3 w; N W插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|