|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
" N) m9 G% e$ ?
2 M' S3 p. t. O; `! r! u; B直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持* v4 R: C" C! ]7 g8 K
8 m$ L6 H( Y( U# p2 X/ A: Z我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
; _$ p; t$ q, W$ }5 P
9 N: G6 J7 B+ ^/ b3 T方便实用 简单 何乐而不用呢
- i' I; x! [ L0 x) k- <?php7 H% S9 E4 a# b2 V4 i% I
- $ f) [, Q7 n/ h1 t1 r
- define( 'ABSPATH', dirname(__FILE__) . '/' );
1 |8 a- V+ z0 i" L1 H - require_once( ABSPATH . 'wp-config.php' );
- H# m. d: Z+ h- i - require_once( ABSPATH . 'wp-settings.php' );
N% O1 R! ?! x) i Z% r - require_once( ABSPATH . 'wp-includes/class-wp.php' );' H- K8 T8 W" {0 e7 B y( K" R
- require_once( ABSPATH . 'wp-includes/functions.php' );
. l( d$ b8 {! H5 x9 P7 G - require_once( ABSPATH . 'wp-includes/plugin.php' );
7 E% p" _( w5 h$ v- P* I* _: D4 T - $title = $_POST["title"];" Q; Z( ~; g* w$ m/ ]( D
- $content = $_POST["content"];7 z) h$ R/ g* k' A$ k2 @
- $tags = explode("_",$_POST["tags"]);9 G/ u3 ~+ C2 Q) [5 h8 M
- $cate = $_POST["cate"];" e/ p0 G2 p2 O! _
- //print_r $tags;
% h3 U8 D( _) c1 I- o* a% _ - //
) G9 |1 G* K1 @ - //
' k# w; |9 u' n+ z0 C" @# S: X - $wp = new WP();
?7 W# \# S* v7 ?: K - $wp->main();; o1 n4 v7 b5 `5 @, o& J
- //9 Y/ j- C. n, j( i' O
- $my_post = array();" U4 C1 u L1 q, {5 a; N- a
- $my_post['post_title'] = $title;
@6 `) ^& l% P - $my_post['post_content'] = $content;6 ]. [6 _: z" @+ `
- $my_post['post_status'] = 'publish';' x4 i8 n( R6 z, q& D
- $my_post['post_author'] = 1;
+ m5 x. d: ~4 w2 B2 K+ z+ Y - $my_post['post_category'] = array($cate);
; k; F( ]* Y& {( _ - $my_post['tags_input'] = $tags;" r/ b6 P ^% F
- //$my_post['tags_input'] = array('tag1', 'tag2');* ~' H: p( Q7 r5 c
- //$my_post['post_status'] = 'future';& V6 o) x: `& T/ A) G w$ D. A3 w( Z
- ////$my_post['post_date'] = '2010-07-04 16:20:03'; G) T0 u, p% ~: O7 J. ?% C
7 c. Q) E* H$ \0 W; z0 P J- // Insert the post into the database) s0 o2 e( U- ? y7 a
- $ret = wp_insert_post( $my_post );
1 ~) g6 C6 A6 Y1 o( z9 O8 A - echo $ret;
6 G' o! T) D+ ~0 s - ?>. U& M6 |6 o- \; V& h: u( {; u3 t
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
9 o8 P, A' ^* T) h- <?php: k3 e4 {8 q/ n3 d# G
- define( 'ABSPATH', dirname(__FILE__) . '/' );
+ e n8 E& m$ o0 Y - require_once( ABSPATH . 'wp-config.php' );
1 |+ r) r! b7 q/ ], I8 } - require_once( ABSPATH . 'wp-settings.php' );$ `1 P3 d: K3 J' X5 X
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
6 Q4 z( S4 G; I# C! b1 K* ~ - require_once( ABSPATH . 'wp-includes/functions.php' );+ J! ?6 P# Y0 M
- require_once( ABSPATH . 'wp-includes/plugin.php' );' A! R- s* R0 \, H/ Q
- $pic_name = $_POST["pic_name"];
5 ~' A3 Q7 R; c: _, Z - $pic = $_POST["pic"];
$ U, {1 n! b! b6 I2 Z - if($pic != "" && $pic_name != "")$ H( ]/ k- K# B1 @4 \. o' H
- {
, k* S; p. N: S; U - $path = "images/";7 r, ~ V7 Q9 u
- $pic_name = $path.$pic_name;
3 |5 B9 {: a; [4 C - echo $pic_name;
2 R( ]6 T6 y T- Q; s - echo "||";. q) _$ L8 t* r
- error_reporting(0);1 Z& u/ K: d5 ~$ q
- mkdir("images");
' h# A0 N _+ }# q1 I6 b - $handle = fopen($pic_name, 'w');
% ?0 m7 K0 _9 V( f( J3 r9 \ - echo fwrite($handle,file_get_contents($pic));' C6 l8 U1 `/ T
- }! p- m' x, G% R, u, E, \
2 i+ Z% Q2 {/ U H x5 c- $title = $_POST["title"];
% \7 N" e' L6 N5 X - $content = $_POST["content"]; Z. e* o: w; m9 P, P
- $tags = explode("_",$_POST["tags"]);% ~& C. B; W3 u- X
- $cate = $_POST["cate"];+ x- |; I/ g8 [6 M: @
- //print_r $tags;' C4 X' e& l4 R, N. _: O
- //% K" g/ y! b" h" }1 }* K
- //
/ b8 ^ t& _3 u# X% W - $wp = new WP();
$ z+ \5 B7 ] J4 x) { - $wp->main();
* B! X" r" z4 F) G) e - //$ D- n* w4 N6 }! w" u9 {3 f
- $my_post = array();
+ ^0 m2 t9 x" k: V- D4 }, R - $my_post['post_title'] = $title; g2 l, o* ]& D) Y- U$ w, O
- $my_post['post_content'] = $content;- H' y2 S- H' k; A
- $my_post['post_status'] = 'publish';
0 |. K% c+ ] d. r* H$ @ Y! W+ t# S2 ? - $my_post['post_author'] = 1;
+ R) v( {1 d, f2 U+ {" G+ Q - $my_post['post_category'] = array($cate);4 S7 Z/ K5 a; z. M, y
- $my_post['tags_input'] = $tags;( |8 i6 o* s8 `" v2 l% f
- //$my_post['tags_input'] = array('tag1', 'tag2');& Z& v3 R! m/ t7 P
- //$my_post['post_status'] = 'future';
6 l6 S& I6 u) e) c - ////$my_post['post_date'] = '2010-07-04 16:20:03';/ ^% e7 s4 }& y9 P
- # E. u2 c; |9 T! f' Z1 R; t- G
- // Insert the post into the database0 b1 {( R9 r$ W6 K8 H$ {' L; y- f
- $ret = wp_insert_post( $my_post );* d/ C4 j5 d7 s- c& B
- echo $ret;: e# d6 v8 m8 l) u `
- ?>
+ b. o z4 x' v) d. a- g
复制代码 我自己写的+ `! p5 }2 q+ P! N" W( X
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|