|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
7 q6 V1 H/ D7 _+ V" X
4 @' L' V0 f: V2 a0 \9 E1 R直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持1 N3 t+ `. x3 G
: E7 u2 O% P3 n e- s& X我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了8 }! s) ]5 K+ \ _
. a7 Q1 R" \2 J! w+ a方便实用 简单 何乐而不用呢
2 D& [: Q) O: h% K. L' f; p- <?php
5 c$ o# i) V6 Y" y' v5 \
* V7 W6 a( \: ^3 ]: H- define( 'ABSPATH', dirname(__FILE__) . '/' );
! a y3 z4 U* b- v' O - require_once( ABSPATH . 'wp-config.php' );
$ S) h, H' N' n, o. s l' R - require_once( ABSPATH . 'wp-settings.php' );6 `% G. x/ [' `9 ^
- require_once( ABSPATH . 'wp-includes/class-wp.php' );6 j8 t9 ~; u. @( `3 Y5 C* e( b4 K
- require_once( ABSPATH . 'wp-includes/functions.php' );. z ?! }7 S4 t8 b3 j) i
- require_once( ABSPATH . 'wp-includes/plugin.php' );
5 L. W Z, q6 O. d; ~0 P I5 F' l - $title = $_POST["title"];
" I9 O7 I. l# E* m, v - $content = $_POST["content"];& q/ T Y# u3 C+ K$ b
- $tags = explode("_",$_POST["tags"]); ?$ _5 I. @. \
- $cate = $_POST["cate"];
( W# \, \, g! D" ~ - //print_r $tags;
& S V" n) J& H' f - //6 x* o! h7 y+ c/ _2 L' G3 Q/ x- _1 l
- //6 g* r; q2 {; n2 X# ~% c- Q
- $wp = new WP();# U* }: [8 Z1 O: k! b" C
- $wp->main();% N/ s9 Q1 c/ P3 H2 \3 Z
- //
/ D1 C* r; Y S" x - $my_post = array();
. v# w! ]+ m5 C _ - $my_post['post_title'] = $title;; Y8 `8 O4 Q0 h. U; M
- $my_post['post_content'] = $content;
2 y! m& F @5 q: g( H/ o - $my_post['post_status'] = 'publish';
; t" `* x. w& p - $my_post['post_author'] = 1; | r c: ]* h! D. I3 J
- $my_post['post_category'] = array($cate);) V2 J: Z& { O4 N' A% s4 e
- $my_post['tags_input'] = $tags;
0 `1 z' v4 {+ F D9 p$ s - //$my_post['tags_input'] = array('tag1', 'tag2');8 G5 }& v$ b/ K# C/ |0 l
- //$my_post['post_status'] = 'future';
% I0 {/ n, _2 {. s - ////$my_post['post_date'] = '2010-07-04 16:20:03';
9 A! H4 ]. R. L/ a2 X
X" ~3 L6 ]3 y6 D, B+ V8 {- // Insert the post into the database4 F8 ^' j G8 l, I% Y& |+ b" P
- $ret = wp_insert_post( $my_post );* _+ ~; ? F/ v2 C1 t) X4 u8 j
- echo $ret;$ f! ?5 I5 U- i3 V! i
- ?>
; d% [. ]! p h& }( v
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
0 @7 s7 W2 o7 A" i! S# A- <?php
: ^, @+ P' L9 W, y% V4 K- [ - define( 'ABSPATH', dirname(__FILE__) . '/' );
. x; K% ]1 Q ^5 H, S - require_once( ABSPATH . 'wp-config.php' );1 H1 t$ @4 e* \4 ?8 [$ I
- require_once( ABSPATH . 'wp-settings.php' );
% K+ ^8 [# {5 q- F4 g% z+ i/ G" Z - require_once( ABSPATH . 'wp-includes/class-wp.php' );
. P q& v0 s S0 | - require_once( ABSPATH . 'wp-includes/functions.php' );4 Y$ M$ w* P" @/ j6 r
- require_once( ABSPATH . 'wp-includes/plugin.php' );' ]' P& d7 m% \( D" |. f7 W
- $pic_name = $_POST["pic_name"];$ K- ]( K3 d: T0 H$ F
- $pic = $_POST["pic"];
0 l, }- `! [" J# A) |" ~ - if($pic != "" && $pic_name != ""), j7 N- T; b1 C
- {2 G3 E% k( e+ A! `
- $path = "images/";, Z. Q! ~) @6 F7 P' b3 [% E
- $pic_name = $path.$pic_name;2 D- ?! [; ]- {/ j' C
- echo $pic_name;
7 \6 J. ]" Y. N9 m# |, { - echo "||";
: F, k& I# _; {/ Z& F* i - error_reporting(0);5 L2 \4 W: `% ] x: @+ l
- mkdir("images");% T6 F" p1 ?, {+ ?+ x
- $handle = fopen($pic_name, 'w');
( @( H. K1 v" r. |! P - echo fwrite($handle,file_get_contents($pic));; W/ r) p5 Y9 X4 x
- }
; x6 i% a8 S8 S6 @1 k- s
- ^2 @8 R$ r, r f: R- $title = $_POST["title"];9 G4 o- J9 \, Q1 s+ B
- $content = $_POST["content"];: B0 B$ V: n" w7 a/ N
- $tags = explode("_",$_POST["tags"]);
# @/ ]* K5 w" N - $cate = $_POST["cate"];+ w# \6 F7 V+ r+ {
- //print_r $tags;0 Y' d! u- g1 X; s
- //
. _2 X) [9 a% |7 U) \7 W+ | - //
- C8 C; R% f( l* j# U0 y - $wp = new WP();
/ @( J! Y$ Y4 x6 l - $wp->main();
$ t0 s& y* H. n: S - //9 |0 c/ k6 h* ?2 [( Z' o
- $my_post = array();
5 I$ H# T2 s' S5 Y8 N- v, t - $my_post['post_title'] = $title;
: m' L7 A) ?6 z& ]0 |6 z& I; w - $my_post['post_content'] = $content;
: W7 D$ s8 \, d* X; d - $my_post['post_status'] = 'publish';
- `7 L9 |4 x/ g5 Y- ~ - $my_post['post_author'] = 1;1 L7 F' z1 \ ~, h, t8 ~' T7 l
- $my_post['post_category'] = array($cate);
$ K8 |: i P! V1 N+ A% p7 e - $my_post['tags_input'] = $tags;
3 F( N& ]* i; R1 e% d+ R4 t& C; s - //$my_post['tags_input'] = array('tag1', 'tag2');4 e+ t7 |$ y |" B4 M6 i; E% `
- //$my_post['post_status'] = 'future';0 a9 k" S( P2 k a1 L" b
- ////$my_post['post_date'] = '2010-07-04 16:20:03';# v6 T6 D5 B/ R6 r" v2 p% R' v
$ d! D' C- M/ ^, h( h2 z- // Insert the post into the database
( t2 B2 y; t) I! ]6 S+ b - $ret = wp_insert_post( $my_post );
- l" g9 V; U$ M0 K9 R' A - echo $ret;
5 Z8 `7 ?: |0 d7 Q: j - ?>0 @) D [3 h. f, G; a1 S% u# U
复制代码 我自己写的0 ~8 t6 V- C0 M; H. z, `, u- S
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|