|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
4 K: _; \, C8 K: O6 G7 |2 b( |2 m0 w Y0 q/ Y
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持7 E9 p9 V: }& _
" d. o ^# I' K) d a: U- T我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
% ?$ u3 i% d" @& r' o
4 w# }/ f- ^. f: [方便实用 简单 何乐而不用呢
- r0 k; L8 U! s: I- <?php R( b* _6 m8 f+ b- n7 ~
- 1 G! k- y' A/ _
- define( 'ABSPATH', dirname(__FILE__) . '/' );- V+ z4 Z1 A8 j$ e! k m5 T
- require_once( ABSPATH . 'wp-config.php' );
: L1 n/ C5 l4 X: a' G% ~8 z; m - require_once( ABSPATH . 'wp-settings.php' );; g( |5 C! s9 S
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
; A6 U0 V$ j' u4 u, U2 l3 a$ b) m - require_once( ABSPATH . 'wp-includes/functions.php' );7 d& q' E, k* g _( i3 ^& g
- require_once( ABSPATH . 'wp-includes/plugin.php' );
5 @$ c0 ~' Z& N/ q: K; C - $title = $_POST["title"];; M3 z/ e3 u7 a. X( l
- $content = $_POST["content"];
) V9 l: H# \2 Y x - $tags = explode("_",$_POST["tags"]);" F4 i( o' h9 ^, J
- $cate = $_POST["cate"];
4 \% h2 ]) l' P H/ E; p - //print_r $tags;
# J' D4 J8 J$ G6 P( A8 g8 i% ` - //# g) {7 n' Z' P+ l: C
- //
7 P0 {: w, }4 a N+ R4 W" C0 d - $wp = new WP();
$ g- f8 M0 B% i& u3 j- Z; V/ n - $wp->main();( C1 s- H0 x9 y9 T
- //
& P9 @0 c) H# u0 P4 z8 ^9 v! y - $my_post = array();
5 k: i3 G/ a, e! N: L1 l - $my_post['post_title'] = $title;) W" }0 \9 W5 Q% h" z: m
- $my_post['post_content'] = $content;
- ]- u1 s& L( Y" E, l6 E8 O' u - $my_post['post_status'] = 'publish';5 P h4 y0 u( X1 X u& w
- $my_post['post_author'] = 1;* R9 F4 S! R2 U) Y9 a7 Z7 I0 ~
- $my_post['post_category'] = array($cate);6 w7 \. `: t! {! d* S* s$ t
- $my_post['tags_input'] = $tags;: r# e1 }* V2 R
- //$my_post['tags_input'] = array('tag1', 'tag2');3 D+ v8 E% p0 z/ p( U9 t
- //$my_post['post_status'] = 'future';
; X4 l6 M: N' v0 G4 ~' P - ////$my_post['post_date'] = '2010-07-04 16:20:03';
6 W- r/ w! v7 _2 q - 0 m( D s6 ]2 R) ~* z* @
- // Insert the post into the database, E" G2 q8 N* s# \" C
- $ret = wp_insert_post( $my_post );6 j: K/ F* l, L
- echo $ret;0 e) L8 h5 [( M! c) @' Q# k
- ?>
. L6 E$ N! }9 R- c8 n
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
2 f+ k) A, x# {4 i. x5 s- <?php; i3 q+ U; j: j
- define( 'ABSPATH', dirname(__FILE__) . '/' );. h/ K0 @; J ^3 ~
- require_once( ABSPATH . 'wp-config.php' );
& {. d' [2 v6 z+ C% ~* d1 k% ~ - require_once( ABSPATH . 'wp-settings.php' );
# J* R8 c8 q1 W/ a - require_once( ABSPATH . 'wp-includes/class-wp.php' );
7 ]3 C. X& T; o; F# B* f. @% M: F - require_once( ABSPATH . 'wp-includes/functions.php' );( D. ]% u/ z, x4 a. N
- require_once( ABSPATH . 'wp-includes/plugin.php' );
% @1 u8 x. [2 c' a' g - $pic_name = $_POST["pic_name"];
0 |- n3 h: z' V - $pic = $_POST["pic"];
; A% c/ j$ Q3 c! ?, L6 L" ^ - if($pic != "" && $pic_name != "")
3 ^) _6 P. s4 x3 w+ _$ z - {
$ ?/ p- p; G6 U! R - $path = "images/";" T" ]1 m8 l, S
- $pic_name = $path.$pic_name;
! R( B: v4 k# G5 P - echo $pic_name;
! q5 T9 o5 A5 E2 Y! n8 }2 {1 l - echo "||";! \& X' d E' j+ ^ ]9 k
- error_reporting(0);
( J1 N2 g2 Y9 i3 F! Y# G! s2 W- [ - mkdir("images");
' ~. Q4 }$ x8 G- q* ` O; ^" J - $handle = fopen($pic_name, 'w');5 _' z( |( W g; n. d8 M7 [6 U) |
- echo fwrite($handle,file_get_contents($pic));. R) j7 m, M/ i& w8 E% G1 i
- }# j1 \$ L, P$ a8 j. O; \% P& A
: `! p8 g1 w' I% Q i8 U- $title = $_POST["title"];
0 [3 S) p* x# t P# U - $content = $_POST["content"];5 P6 ]! n1 v0 S) X" e0 [& a8 v( e8 o
- $tags = explode("_",$_POST["tags"]);
% w8 v0 V n' H1 K7 _8 z - $cate = $_POST["cate"];
) {, d; H' n+ z( a; v- L: d" P - //print_r $tags;$ x9 z0 H% f9 ~, R
- //
& t4 b( g V# I" { W7 @# s - //
$ Y9 z$ r F, J$ ?3 E" k1 j - $wp = new WP();. S4 O/ A$ x- d3 B2 x1 y5 {1 B/ U" e
- $wp->main();
7 w) G6 _) L- P0 c# H - //4 ?4 `$ J9 w) `6 ~* F
- $my_post = array();( r1 ^ g: C1 h: M2 S# ^
- $my_post['post_title'] = $title;
" I ?9 r8 P i6 ` - $my_post['post_content'] = $content;/ Z$ E* v5 s$ I3 }7 F T. W
- $my_post['post_status'] = 'publish';
* g; P3 a0 T% B" a/ G) O - $my_post['post_author'] = 1;
" c& q. b2 M9 o) k' b6 W - $my_post['post_category'] = array($cate);! Y: B4 B% ~$ i
- $my_post['tags_input'] = $tags;1 `2 D i' K/ b6 G
- //$my_post['tags_input'] = array('tag1', 'tag2');
8 C4 |0 h+ |2 @ - //$my_post['post_status'] = 'future';4 x' D/ ^* {% B, k
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
7 V" p/ D9 x, d! l; w+ B2 Y; I" a! f
4 m# w5 D) I& a- // Insert the post into the database
; q0 S3 D# E5 }' |( p& L) [ - $ret = wp_insert_post( $my_post );
$ f; U3 Y: ^" W7 Z - echo $ret;: _0 _9 G/ Q: q ]
- ?>
w; x% {' w2 A: c1 @( S1 v2 V
复制代码 我自己写的: {; ?/ V3 P5 I/ c$ p3 Y9 v
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|