|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
7 j" r8 w+ |+ Y( u$ o6 |4 o p* ^/ F* u
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持, U* Y( ?* n6 n
- U$ h8 I d; F2 d我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了& M1 b, M; Y; P$ |( u! p5 R
" N/ L, ~6 u8 f) Z. I. i( Q |方便实用 简单 何乐而不用呢
/ f1 p* p( K. r3 I0 d- l- <?php
1 u) F) y: ]+ {3 q
3 g. ^ y1 N' g, s0 X+ x- define( 'ABSPATH', dirname(__FILE__) . '/' );
4 @5 y$ V {$ I - require_once( ABSPATH . 'wp-config.php' );
4 d' ]' V7 V/ l2 y - require_once( ABSPATH . 'wp-settings.php' );
) l1 c+ A0 H( h o - require_once( ABSPATH . 'wp-includes/class-wp.php' );7 U/ a& q% W L
- require_once( ABSPATH . 'wp-includes/functions.php' );
$ d' _: p+ t2 s. ? - require_once( ABSPATH . 'wp-includes/plugin.php' );
) G3 v* f% W8 r1 l - $title = $_POST["title"];
# L- Q2 s0 d# n5 s* x7 d; P% ]! u - $content = $_POST["content"];8 \" k% f6 [5 O6 y: h, Y) C
- $tags = explode("_",$_POST["tags"]);
1 @: P: [/ O0 ?/ [- ~$ [8 b) q - $cate = $_POST["cate"];3 ~( m2 x! @+ Y
- //print_r $tags;& B2 g, h7 Y# o. A: c+ [ h
- //) j% D+ ]0 e1 r7 r
- //9 b* a2 r- |5 l' C2 c1 I8 V
- $wp = new WP();
4 Z! c3 ^, R7 ~. l- V- ~ - $wp->main();
. G7 a% g% U, p3 O - //
& I5 m, u6 X" X# l8 S& F/ _! P2 K+ e - $my_post = array();
5 x+ R7 \/ P6 h+ a - $my_post['post_title'] = $title;" c7 @9 P" m# x" d
- $my_post['post_content'] = $content;
3 A; K( U p6 D5 H( l& k# v+ X - $my_post['post_status'] = 'publish';
4 K# A- g: \3 |8 B1 ?/ u - $my_post['post_author'] = 1;
6 F- p* \. u$ i4 X - $my_post['post_category'] = array($cate);" h7 ^, C! \1 A
- $my_post['tags_input'] = $tags;% e% k' `* [- O+ V5 H
- //$my_post['tags_input'] = array('tag1', 'tag2');% h: \1 q1 F% G7 e( ?
- //$my_post['post_status'] = 'future';- R0 U: \' y* S" ~+ u/ S9 q! X: O5 {
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
0 I0 ]( ?9 u/ ~! f - " q" L J. a- a& U q* @
- // Insert the post into the database% v, p0 p8 {- l- \: [# s# s. o% d
- $ret = wp_insert_post( $my_post );
9 @/ q# T% k" n8 K7 m - echo $ret;, T/ c% P) T" S: j% P' T3 g
- ?>
1 M2 G% R5 P4 n6 F0 E6 ]. R: @. ~
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
# N1 q$ b5 o! _! `3 D: h' p" m- <?php
, m; _7 k! C9 R7 A - define( 'ABSPATH', dirname(__FILE__) . '/' );
! |- R" a: X8 U7 V A/ U - require_once( ABSPATH . 'wp-config.php' );
6 t. q# O" J" i; \( A( q7 ] - require_once( ABSPATH . 'wp-settings.php' );! W- ?; P F+ b/ T, h2 S" y
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
3 I; R) |4 ]% S8 L! Y$ w - require_once( ABSPATH . 'wp-includes/functions.php' );
) n9 m! |$ q4 S; m8 c( E4 d8 b - require_once( ABSPATH . 'wp-includes/plugin.php' );1 x: j/ i0 I q a- r
- $pic_name = $_POST["pic_name"];+ n& ?- L2 w0 V3 ~* P7 u/ N
- $pic = $_POST["pic"];
& N. |( ?; T& c' N - if($pic != "" && $pic_name != ""); X) ^( m) Z; X; i: b( A
- {/ e) E+ U/ d7 d {: T" r9 g
- $path = "images/";7 k' B( E4 p( C; |
- $pic_name = $path.$pic_name;
: A( f( ]: n0 h" { - echo $pic_name;
" w9 y2 u& X6 c Z - echo "||";
1 C. y7 P/ ^- t$ g5 l - error_reporting(0);1 o! b0 E- Z# o, w* _# Q
- mkdir("images");% t# c6 C! o. | W+ y& n5 j* w, r
- $handle = fopen($pic_name, 'w');
7 \/ x7 u! o; f: i$ L5 y - echo fwrite($handle,file_get_contents($pic));8 Z! p( o7 K2 V0 l" C1 L' g4 K
- }
+ J) z/ m. H/ A& F6 v - . c C( G# p$ p7 L6 e
- $title = $_POST["title"]; F' e. r+ k; a7 G
- $content = $_POST["content"];' O0 _" O% |: R. p/ f1 a7 ^
- $tags = explode("_",$_POST["tags"]);. F, `/ v( w+ h8 Q
- $cate = $_POST["cate"];( B E6 T0 F# L, }, U
- //print_r $tags;
4 d2 E) ^1 A) P3 {2 `* M9 C! C A - //
) J }( Y5 O" m5 f3 t - //& M0 P% x) G) m
- $wp = new WP();
. } h8 [" |1 C" Q - $wp->main();+ K e0 r; M+ [7 i5 n: r
- //
0 @' \2 e0 V% {" p# Z5 s - $my_post = array();! K$ r0 L% o C3 n! r
- $my_post['post_title'] = $title;
6 u& C: l4 Z& t - $my_post['post_content'] = $content;
9 s6 I! i$ M& Q: Z2 Y d' y+ t9 _ - $my_post['post_status'] = 'publish';6 }5 h) Q8 W+ F, s
- $my_post['post_author'] = 1;
- v; M) t$ A, }8 s/ O - $my_post['post_category'] = array($cate);
7 E( ~- o/ q+ ^' i - $my_post['tags_input'] = $tags;# f% X9 {; v/ x
- //$my_post['tags_input'] = array('tag1', 'tag2');! O! O1 @- J- H: D2 J/ k3 @% K
- //$my_post['post_status'] = 'future';2 z3 U, s" W& U
- ////$my_post['post_date'] = '2010-07-04 16:20:03';0 H$ V$ q( s. A9 Y; w
& V8 M1 j! p b/ i- // Insert the post into the database
& D. J. s8 C/ L; P - $ret = wp_insert_post( $my_post );$ i3 P/ ?& x0 |# l4 f
- echo $ret;
) K5 _4 X+ P5 f [8 j - ?>
/ O- Q! ^ A6 A# _
复制代码 我自己写的
0 x6 ]4 }: a$ L, U1 X插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|