|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
2 V x1 k6 O9 X. n8 A5 \+ q; { M/ V7 W" v w
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
4 g: @7 U8 R' N$ g0 p( i7 T: n4 |( h) x+ [7 u8 I
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了( {# f2 `4 }! p) l. p a9 [) I3 A
+ P: ?, @5 G0 ^# H9 a方便实用 简单 何乐而不用呢
' g& `5 {( H, c- <?php
4 w# A' r) `' C ^5 n - " M- u. X0 P( ~! @; N- g! F
- define( 'ABSPATH', dirname(__FILE__) . '/' );! Q" h) U% \. Z
- require_once( ABSPATH . 'wp-config.php' );+ d5 J# [7 C; K' h1 g5 v
- require_once( ABSPATH . 'wp-settings.php' );
, k. C, M6 r9 z$ s) Z - require_once( ABSPATH . 'wp-includes/class-wp.php' );" ^5 P4 u+ s% I K/ y) ?! a( K/ H# K
- require_once( ABSPATH . 'wp-includes/functions.php' );
2 Y* V1 B8 Y* s+ G t9 n( B- k - require_once( ABSPATH . 'wp-includes/plugin.php' );8 a4 ]9 U5 T, Q/ ]% x
- $title = $_POST["title"];9 a! G7 F/ C$ q H
- $content = $_POST["content"];
5 `; S9 x# }1 y- m9 C! a6 ]5 f. A _ - $tags = explode("_",$_POST["tags"]);8 D1 W; t* N2 r# s* M+ A% f
- $cate = $_POST["cate"];# p, ^* H" h+ o
- //print_r $tags;! c6 X' T0 W' ~& u. n) p
- //! R q; r6 l7 C! m3 u
- //
, W- [8 k: \( c* C7 J - $wp = new WP();
" Y6 G5 h& ]# V* w( ^ - $wp->main();) p! W' g' F) w: C- {. q
- //) \/ X4 ]" R* }
- $my_post = array();8 v7 ~) x5 v4 J" H6 z: g
- $my_post['post_title'] = $title;4 ]- w: ]4 T3 X) b
- $my_post['post_content'] = $content;! e* _' o: |, Q1 I. w9 n
- $my_post['post_status'] = 'publish';
# F+ G. t3 r0 h, O - $my_post['post_author'] = 1;4 ` j7 J. G8 I5 q7 v
- $my_post['post_category'] = array($cate);
: D) r4 ?3 {% n/ | - $my_post['tags_input'] = $tags;9 [1 q. A5 Q$ p( \$ ^% ^
- //$my_post['tags_input'] = array('tag1', 'tag2');0 S4 A( _, j0 S0 R% s& s5 V! Y6 |
- //$my_post['post_status'] = 'future';0 z5 r. O* {3 ?8 c5 y! s" P& p
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
/ w' T/ d3 z: o( g- W3 n - * C. x. ~; H' _1 [
- // Insert the post into the database. N, R; w' V/ U( e
- $ret = wp_insert_post( $my_post );
- a* l: L3 ?3 p a - echo $ret;
( n% m' u: G7 S5 V: b - ?>
( l0 E9 d- R5 u8 |
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 3 q* R. N1 T$ B& c L
- <?php
) C: B/ s2 E- f+ s - define( 'ABSPATH', dirname(__FILE__) . '/' );- c1 m9 ?. ^* y" N/ Q
- require_once( ABSPATH . 'wp-config.php' );
/ f. p5 t" Y3 L8 d8 S9 Z7 ?9 I5 U - require_once( ABSPATH . 'wp-settings.php' );
) p- i" l5 c6 O& s0 D4 V - require_once( ABSPATH . 'wp-includes/class-wp.php' );% s. E/ o0 G3 J9 d) I
- require_once( ABSPATH . 'wp-includes/functions.php' );& s% |; _; Z$ G$ S6 u' @' u
- require_once( ABSPATH . 'wp-includes/plugin.php' );) K( M8 q9 a! G/ |# _" R) e( J
- $pic_name = $_POST["pic_name"];& E" I: f8 j8 o6 y! V. A
- $pic = $_POST["pic"];) c- W: h# w' D8 V9 D9 F
- if($pic != "" && $pic_name != "")% C9 C6 V S# r$ A) X/ }
- {1 f/ X6 f+ A, F& q; k4 ]0 I
- $path = "images/";- q M% C ~" `; k! D- A
- $pic_name = $path.$pic_name; [3 K6 V) D. x; o. Z$ | A0 I% R2 w
- echo $pic_name;, y! x8 T1 B( V2 [" I4 L
- echo "||";
) |0 ~1 h+ q: O - error_reporting(0);
[, k' v" q. H, `1 E" h, ]" U - mkdir("images");( s1 x5 {2 ?7 }7 p `' v5 P
- $handle = fopen($pic_name, 'w');
- J1 [" ~! L& H - echo fwrite($handle,file_get_contents($pic));
( u: _! Q; i: x4 b) j' x- x | n8 O - }0 U: Q2 ^/ u5 f' k( ?
- $ O7 O7 G+ z$ w# s
- $title = $_POST["title"];
- _0 x& S/ v4 n* ~ - $content = $_POST["content"];8 w' I- z) y3 U/ d& I* \. H
- $tags = explode("_",$_POST["tags"]);) h5 ~' O1 k7 w% m4 f0 J
- $cate = $_POST["cate"];' |6 m' D1 T# B, T$ B! x& f
- //print_r $tags;- u C1 r! ~; d5 k9 o0 u! d
- //* |: p& l. Q3 _2 s4 Q9 [
- //1 b- H9 ?/ X0 [( \
- $wp = new WP();' b) o/ p" D8 @9 M
- $wp->main();" Y& c6 R- }2 b. E
- //
& H) m3 }& e3 h3 M - $my_post = array();
( {9 ~2 v3 C/ ^7 N% o - $my_post['post_title'] = $title;
7 P8 e% n: E* z# d. t- I$ ~7 | - $my_post['post_content'] = $content;/ h8 a; f( c/ `) k/ q+ F$ q
- $my_post['post_status'] = 'publish';
" g; `) g# [$ }4 p0 f0 I* E - $my_post['post_author'] = 1;/ J% N6 T1 d. h1 J+ P
- $my_post['post_category'] = array($cate);0 k' W4 c0 J( w
- $my_post['tags_input'] = $tags;/ S& R1 U; y( m+ P' D: [
- //$my_post['tags_input'] = array('tag1', 'tag2');
* R/ ?) K, g& ` B6 Y: @8 I3 m - //$my_post['post_status'] = 'future';5 r; H1 B/ S6 [) [" i
- ////$my_post['post_date'] = '2010-07-04 16:20:03';$ l0 l& ~, P0 z
- % f& O# K/ v7 z+ m( f, i
- // Insert the post into the database2 }; w2 W% ~ x4 D( v
- $ret = wp_insert_post( $my_post );
0 L3 u/ w: F$ l7 G- k. r - echo $ret;
1 E9 j% B1 G. A8 ~+ U4 @6 m; b; y - ?>
$ U; b: r+ I& @0 l4 x( V# \
复制代码 我自己写的3 x" M7 P1 H3 {2 ]3 C( Q
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|