|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
$ m/ M$ d) T/ M- Z, d
% v5 E6 h3 F2 Q- n直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
- F9 G9 C1 p) j( o$ |* _, |& Z( R5 k
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
: j5 T! p( K/ j6 u7 `+ m9 J+ p+ u# t$ O: X# Y8 S
方便实用 简单 何乐而不用呢- ( N& f% c# \ b) _
- <?php4 B" ~6 I% @* l$ [% Z* d
, {+ L, U2 g+ t+ @8 _- define( 'ABSPATH', dirname(__FILE__) . '/' );
2 I- C& j8 k+ d% d1 B5 A - require_once( ABSPATH . 'wp-config.php' );
$ N" I- n. h- F2 j6 N/ a) h" q - require_once( ABSPATH . 'wp-settings.php' );% U4 r5 i! m6 K4 u/ M5 b
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
9 P1 \% n3 B) G5 F# K% [ - require_once( ABSPATH . 'wp-includes/functions.php' );
& ^$ g1 f. S+ ?4 [+ Z - require_once( ABSPATH . 'wp-includes/plugin.php' );3 C- c6 W+ w D, t5 B
- $title = $_POST["title"];" m* R3 C: V6 E) ]
- $content = $_POST["content"];2 @) Y# ^& | b. n
- $tags = explode("_",$_POST["tags"]);+ ^: ]% O; _' [* o6 e
- $cate = $_POST["cate"];
7 f% q1 ]( F; e8 r/ M - //print_r $tags;* X/ e! O: T1 ]( U1 L
- //! _+ V" c: t" S3 F( j& y# f
- //
/ w0 z* s5 X' {9 k# F - $wp = new WP();
! @' j q. x% d - $wp->main();
' Y0 @' ?& Z% ]' P1 @ - //& l1 l6 k8 Y0 V% x. V# R
- $my_post = array();
: F" h: g) C: Y( [/ ~ - $my_post['post_title'] = $title;
6 r$ \5 U- G* r8 H* E - $my_post['post_content'] = $content;
9 Q/ c2 C- Z4 W% X* O - $my_post['post_status'] = 'publish';9 s1 n' ?- ^6 i6 w; q
- $my_post['post_author'] = 1;2 f: P7 K2 [! [# a" s0 v$ T
- $my_post['post_category'] = array($cate);
; ~ }0 W" ?. O/ ~+ n' S - $my_post['tags_input'] = $tags;3 F3 C# W3 Z9 L& S% O
- //$my_post['tags_input'] = array('tag1', 'tag2');
+ h1 Q/ b F8 }. n& C - //$my_post['post_status'] = 'future';
* m7 t! I% [% O3 N% t F) o - ////$my_post['post_date'] = '2010-07-04 16:20:03';
3 p8 V0 v6 b$ K5 }+ ]) g l0 l - ; {( O$ _( V E# z
- // Insert the post into the database2 W; t6 w" i( q- Y; f
- $ret = wp_insert_post( $my_post );( G3 \9 S$ H- O; m
- echo $ret;
5 @# e7 w& S3 z: o - ?>
5 s& H( E3 n0 V
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 2 {) y! m6 y a2 V
- <?php
4 ?( Q2 q; j2 W+ _, k( W - define( 'ABSPATH', dirname(__FILE__) . '/' );
; Z* ]$ k* O: [. U# a4 p2 k" q; G6 M - require_once( ABSPATH . 'wp-config.php' );
" G' l! M9 A" |9 O7 g - require_once( ABSPATH . 'wp-settings.php' );
! }% p4 R+ M- r e2 P3 J v) N" s6 ` - require_once( ABSPATH . 'wp-includes/class-wp.php' );
& f' n! g7 _, F& t# b5 T. _ - require_once( ABSPATH . 'wp-includes/functions.php' );; \% E& N9 i) x: e: g8 \" i
- require_once( ABSPATH . 'wp-includes/plugin.php' );% [4 D9 {; N, H( ~
- $pic_name = $_POST["pic_name"];& z t0 |! w4 ?. v5 f( M
- $pic = $_POST["pic"];# U4 L3 m- v, Y4 K7 [) n9 F" z
- if($pic != "" && $pic_name != "")6 c {" z8 z" E; _, Z' _
- {9 p! U6 Y( y8 l- w1 w
- $path = "images/";
% @# o* c0 @; P# Z/ e - $pic_name = $path.$pic_name;2 _% e# I' x" ?
- echo $pic_name;) F+ Z! T8 Q. g1 ~
- echo "||";! s G7 z$ d _
- error_reporting(0);% h9 P- s% t' x& C5 G) F
- mkdir("images");
K! \* S, V( [* ^, x9 R' V - $handle = fopen($pic_name, 'w');, _3 T5 {+ [3 s- g( D* y
- echo fwrite($handle,file_get_contents($pic));+ J% d8 h3 e1 R/ t% R
- }. H/ | J" B5 d' h
- 4 ^9 @# Z0 z/ a
- $title = $_POST["title"];, k- ~. K# J3 g0 X
- $content = $_POST["content"];
6 O8 F* o U/ H- C& U+ B& x - $tags = explode("_",$_POST["tags"]);, F+ [8 }, u& }2 u( z4 L# v/ F
- $cate = $_POST["cate"];5 n4 O! Y# y; [7 _, W$ T
- //print_r $tags;
$ U v: F4 q9 D* I6 T) L3 t - //! y% U+ s6 i7 D( O0 m
- //
& h, k- B# H8 T- A - $wp = new WP();
# u# U4 E! Q" \" L2 | - $wp->main();
: R2 a; l- P0 O8 F# e - //
+ Z1 W) r8 ?4 J - $my_post = array();8 u' T/ @, ]8 Z9 O }, @
- $my_post['post_title'] = $title;
% X1 {1 L! N% B- c - $my_post['post_content'] = $content;/ K4 R3 j7 w/ U( y* U- t
- $my_post['post_status'] = 'publish';' T( E& `1 i% h6 C9 d
- $my_post['post_author'] = 1;
7 H3 [/ U& C- e: M+ H( }6 G+ ]+ u4 I - $my_post['post_category'] = array($cate);
. L" n' O5 F+ n2 P - $my_post['tags_input'] = $tags;* ?3 a( Z, `, I& @
- //$my_post['tags_input'] = array('tag1', 'tag2');# v2 P7 `8 I7 T) }
- //$my_post['post_status'] = 'future';
. j/ t* x/ I( }) w1 h - ////$my_post['post_date'] = '2010-07-04 16:20:03';, C( U/ }% g. k1 {6 G7 d
- $ [! {" y5 }4 W* `/ I
- // Insert the post into the database) i d( S$ j( G2 i: l9 [
- $ret = wp_insert_post( $my_post );
+ \3 A$ [. t- b1 o8 |; J# E; F7 g - echo $ret;2 c# K: `9 E T9 S; o, b
- ?>
+ f* h# p" m) ^ {
复制代码 我自己写的% t( U) c( b) j1 e
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|