|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
; q! q4 s- x! q* x2 \: s, ?2 @$ f# w- A6 M
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
9 u4 x G3 c+ h
3 ` Y" b) l* p# x1 c; g我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了4 x3 _7 r7 K. m% r' B9 O& R
6 I- Y! D/ y& r' {; x
方便实用 简单 何乐而不用呢- & v( l3 h* L# }
- <?php
; m+ W w0 H6 \1 T; m6 h
% w9 \$ t' w5 Y* E! O3 U- define( 'ABSPATH', dirname(__FILE__) . '/' );
4 E+ A1 ? V/ E5 L# ` - require_once( ABSPATH . 'wp-config.php' );
, I# {* j/ T2 o" _9 S- M" } O* e - require_once( ABSPATH . 'wp-settings.php' );) H& I+ w) s; Y9 U0 ~5 ?3 M
- require_once( ABSPATH . 'wp-includes/class-wp.php' );2 ?2 V" n& W3 [
- require_once( ABSPATH . 'wp-includes/functions.php' );8 Q& R# B/ R" F8 X$ m
- require_once( ABSPATH . 'wp-includes/plugin.php' );
]2 b5 D2 ^+ [$ b) e - $title = $_POST["title"];) e. G" v2 S) ?' c0 H- r
- $content = $_POST["content"];
1 K! e4 \/ H- e0 y( q- V+ ` - $tags = explode("_",$_POST["tags"]);$ h+ b4 X1 E; ^( n: F# J
- $cate = $_POST["cate"];8 ~* N1 U* g: C7 D" {2 h. w
- //print_r $tags;0 W" c; U: r, Y& I6 l
- //4 y% R; {& w; a# g9 T, k& g
- //
+ }: d, Y( ?! c6 l7 {% R$ ^5 O - $wp = new WP();
% w9 S+ u/ L9 g - $wp->main();
# Q4 @; y/ E' K+ }, @( O0 z) i - //
2 k( Q, b4 ?1 B8 ^' E - $my_post = array();
' C6 }. d5 s& L2 Y) w; J" c - $my_post['post_title'] = $title;
# Y1 C* p6 E# e! ?/ V - $my_post['post_content'] = $content;* T; [* o8 l( h* l, z
- $my_post['post_status'] = 'publish';% K x+ f( ?' L8 u
- $my_post['post_author'] = 1;0 p0 D0 y& o. L$ n/ d
- $my_post['post_category'] = array($cate);
4 X% h2 [2 }9 b' ^ - $my_post['tags_input'] = $tags;0 f' D' r% V- G' [7 ^
- //$my_post['tags_input'] = array('tag1', 'tag2');; C" U" N x' s1 @/ V# o
- //$my_post['post_status'] = 'future';
) p/ D. E& T" p - ////$my_post['post_date'] = '2010-07-04 16:20:03';! l [$ U& x8 D7 Y) K' z( v
/ o# u6 ]0 S1 T/ j1 X6 i- // Insert the post into the database
/ \8 b9 I: `9 z5 O+ v2 {$ e' l - $ret = wp_insert_post( $my_post );$ h: t0 V* l( c6 ^, x+ a; \
- echo $ret;
! F( V/ c0 c$ e' y - ?>
% S j& ^, K" P. }3 k( T# g0 A
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- + q9 V# y. W& H$ H) o9 T
- <?php
- b8 R) J. j6 ~0 u: K, ~ - define( 'ABSPATH', dirname(__FILE__) . '/' );
# M+ ?" U5 L% W) l - require_once( ABSPATH . 'wp-config.php' );
: I J" l" `) C - require_once( ABSPATH . 'wp-settings.php' );0 a# e4 [% W9 x6 e& d5 n8 A
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
/ u( ~8 l: S8 ~! R - require_once( ABSPATH . 'wp-includes/functions.php' );
1 {) E' e6 M' j; N; N - require_once( ABSPATH . 'wp-includes/plugin.php' );
+ G% Q$ q5 }# g8 `+ S4 f - $pic_name = $_POST["pic_name"];- e- o( R& u8 d. q1 F/ A
- $pic = $_POST["pic"];2 N& }" _/ N% J# C: _" Z* D
- if($pic != "" && $pic_name != "")
" e) [( \5 H( u1 [ - {3 g( X' j; S! q, ~* E1 m/ S- o
- $path = "images/"; G6 }# J, k( B% T
- $pic_name = $path.$pic_name;
+ q% ^3 |7 O) P0 U! W - echo $pic_name;; b! q. B' w6 v+ k, q) ?: q
- echo "||";
# d6 s+ q% }- O- ^ - error_reporting(0);
+ q6 m4 v" z2 v# _3 U! U - mkdir("images");& e( G* I+ p# C4 H- O7 T
- $handle = fopen($pic_name, 'w');
' W* D3 [0 P( j; a" B - echo fwrite($handle,file_get_contents($pic));
* K+ f% O: B. |# k+ S1 f( ?' U - }
4 w4 k% h- Z6 ~$ q
+ ?3 F% r, U3 t- $title = $_POST["title"];5 F4 {& S3 l, e( o) N
- $content = $_POST["content"];4 S( Z1 a1 b/ H2 l0 ]5 _9 v
- $tags = explode("_",$_POST["tags"]);
, \1 }! m8 }9 b9 H, N4 d - $cate = $_POST["cate"];
! x% ^2 Y9 ?0 T$ A3 I+ K9 x. q - //print_r $tags;
5 P: Y8 }- x. k - //: o2 G& c% r5 E1 @- w4 a( v
- //
: U* e' e- j) \1 x0 P - $wp = new WP();( H3 O; [! P* m K0 J
- $wp->main();
9 ? r: F, ]! P5 b- P; h6 {* | - //
% l% D% K! q5 e. @5 ~ - $my_post = array();' Z, x! a1 Y) m4 {$ |4 }% k
- $my_post['post_title'] = $title;: e- F) B4 |/ c8 _6 D' g2 v0 v
- $my_post['post_content'] = $content;
! m( J/ r- R S! h* h - $my_post['post_status'] = 'publish';
0 D7 o) [; s; V/ } - $my_post['post_author'] = 1;& ]0 ~' Q7 y3 |* n+ r' u
- $my_post['post_category'] = array($cate);% V. f, c& b2 a" o L
- $my_post['tags_input'] = $tags;7 J$ `. V5 w0 x Z/ D9 W9 z( \9 j
- //$my_post['tags_input'] = array('tag1', 'tag2');+ T- I& f& |. l- q0 H
- //$my_post['post_status'] = 'future';
! _) d$ l4 z$ X6 L) _ - ////$my_post['post_date'] = '2010-07-04 16:20:03';
: N( Q# \ Z- N9 {% t
) g* |; ^+ C4 N! f+ V$ p1 p: s- // Insert the post into the database( g8 z9 z% U( H* u3 G" g
- $ret = wp_insert_post( $my_post );
9 K8 L8 ^) Z; H0 q4 z - echo $ret;
3 G( p' | K+ u% u - ?>$ ^* E* O, l7 Z9 p8 \
复制代码 我自己写的
' [+ R: I7 V9 Y0 z3 m插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|