|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
b8 X! F, @- o+ Y) [0 ~. Q, N3 j. ~/ Z1 s8 j9 H3 u' `8 Z, Q; ?5 Y' M5 B! ~! F
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持% ~% v9 M6 I3 M) a, F0 n1 g" E
$ ^/ G' ?1 F s/ p- ~7 w- h) ^我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了4 v7 {# O4 Z/ p6 I1 K, b# d
' [/ V( K7 `: R, l2 `( Y6 o$ Y- o方便实用 简单 何乐而不用呢- : F) J! i7 G3 s4 d& r
- <?php! S( @2 p4 w5 H+ P
T* ?- t+ l2 ~: X& y8 _- define( 'ABSPATH', dirname(__FILE__) . '/' );6 o" s) Y8 y. ]$ @9 J
- require_once( ABSPATH . 'wp-config.php' );
# B1 v/ {. Y; h - require_once( ABSPATH . 'wp-settings.php' );& v# `, {+ u+ \+ `) Q
- require_once( ABSPATH . 'wp-includes/class-wp.php' );, |/ P! a/ S, y7 D
- require_once( ABSPATH . 'wp-includes/functions.php' );
$ E+ x& r% {3 I8 v: K( e. @ - require_once( ABSPATH . 'wp-includes/plugin.php' );
V# k4 e0 Q" s% n* }9 x - $title = $_POST["title"];
- s# J2 F( Q7 u. `/ p% e' C - $content = $_POST["content"];
! C0 ~! z- L1 g/ p - $tags = explode("_",$_POST["tags"]);1 C1 x) s1 \$ g
- $cate = $_POST["cate"];
9 |3 c a9 j- U* B6 C: g - //print_r $tags;
- t& R9 s4 ]8 J7 s$ t - //
7 G6 l0 v# M; e( H* { - //
^; ]/ {2 I) p. N2 \- T - $wp = new WP();: P1 ?4 G5 K# H# }1 F
- $wp->main();1 u& `5 Z1 h4 d4 g. ~) y/ o
- //8 G& b0 w# l; j# v7 V, [+ L/ [
- $my_post = array();* f" ?) u8 L+ \% F
- $my_post['post_title'] = $title;
# {9 o6 ~ H* v$ D3 w/ E - $my_post['post_content'] = $content;7 |3 u% L5 R' v9 ]
- $my_post['post_status'] = 'publish';. N# j6 R* Q" Q6 m
- $my_post['post_author'] = 1;
# o, d2 H O5 ?3 S - $my_post['post_category'] = array($cate);
# ` }! }6 o- m6 ^$ c - $my_post['tags_input'] = $tags;
m# {. E% V+ Q, S/ i - //$my_post['tags_input'] = array('tag1', 'tag2');
+ J$ [" v" N: C$ t$ d; U5 I7 M- y - //$my_post['post_status'] = 'future';
. n- m* S1 N7 z3 [, R - ////$my_post['post_date'] = '2010-07-04 16:20:03';) L& x1 l1 m! P* d# w( \
' T- r5 ]2 C" p1 g1 ]- S, a4 ]! ^- // Insert the post into the database
) G1 V9 C% U/ G - $ret = wp_insert_post( $my_post );
! k ]7 m. O6 ]" f/ A1 A: o! |3 J) _' N - echo $ret;1 m+ X, h, Q2 D! \5 K3 @
- ?>
: }1 {$ }3 d, D
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- * ^2 O& g c9 N2 d1 L
- <?php0 P) K+ R) E; k# x
- define( 'ABSPATH', dirname(__FILE__) . '/' );
/ r; v, v0 _6 [ - require_once( ABSPATH . 'wp-config.php' );
i3 v) v$ Q. L! `6 Q9 V - require_once( ABSPATH . 'wp-settings.php' );7 v4 \+ Y+ h; g4 l8 w# E' Q0 M
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
+ d1 A" e* S' t5 i( r - require_once( ABSPATH . 'wp-includes/functions.php' );
( f8 ?2 c+ h d5 W" |- D/ G - require_once( ABSPATH . 'wp-includes/plugin.php' );
' C+ o% G1 N, [1 X - $pic_name = $_POST["pic_name"];
! X# Y& D7 U& ?! H" s) w) W - $pic = $_POST["pic"];
2 [' y) s2 Q/ ]3 o1 ^5 \8 C - if($pic != "" && $pic_name != "")
, D9 T& m% \7 g! a. P - {# l7 V% |( a) q+ C
- $path = "images/";
: g, u) b5 X" M& Z( u1 }& D" z P - $pic_name = $path.$pic_name;. U8 m+ q" w8 ^! [! r0 Y
- echo $pic_name;( s, D" r' b% z+ B1 H
- echo "||";
& S: c9 z: y2 L; R4 o" i5 P - error_reporting(0);
' b& Y! [" o/ k4 p8 y' q/ K - mkdir("images");
8 Y& y! p4 j0 s2 ^% u, H& V - $handle = fopen($pic_name, 'w');; y( ?1 o4 o6 A; E: w4 j# F1 y$ j
- echo fwrite($handle,file_get_contents($pic)); z! _/ R4 c, B
- }8 ]9 e. O0 w! h5 r( k
7 I# q6 H j. I: y* `- $title = $_POST["title"];
) y' a3 r! } ~" ?3 Z& P( @! i: m - $content = $_POST["content"];6 @6 W8 `4 ^' I
- $tags = explode("_",$_POST["tags"]);
4 E7 U; e T* ]$ L9 [- G# M - $cate = $_POST["cate"];& a8 R, [* Q @5 \* k2 L
- //print_r $tags;" y8 h) K, ?: o) ^$ E
- //& M' U1 A0 K2 g0 Z) N1 b
- //
$ U7 C# v8 s4 m' k9 h - $wp = new WP();) s5 ]* e h9 z% e! z
- $wp->main();! Y8 [ @* j; a4 r
- //" ^: `9 R( m( M! r0 i6 j
- $my_post = array();
6 Z& c$ h4 W# i - $my_post['post_title'] = $title;2 p9 O3 j9 J0 r" Z& F
- $my_post['post_content'] = $content;2 k6 Y9 \% m, _6 w+ C# q; ~/ C
- $my_post['post_status'] = 'publish';/ t" Y c2 ]1 A/ t
- $my_post['post_author'] = 1;
) \ }1 I3 Q: w( R2 h3 c, ~4 Q - $my_post['post_category'] = array($cate); i3 u7 |. b# H' S
- $my_post['tags_input'] = $tags;
# w2 u: q8 h4 _5 G" A - //$my_post['tags_input'] = array('tag1', 'tag2');
1 { B) k a# q* q- ^, X - //$my_post['post_status'] = 'future';
8 ^# p' q- {: z% | - ////$my_post['post_date'] = '2010-07-04 16:20:03';% f1 a: i6 {! g3 j/ z. O' Y
9 g$ E/ Z2 y8 v( O" d- // Insert the post into the database
; V# J* ^! v6 g0 u+ U - $ret = wp_insert_post( $my_post );
: ^ i" c9 Q) ? - echo $ret;
. V' _' G. A& b2 H - ?>
8 t9 C. K) q- X0 P/ L
复制代码 我自己写的
2 F" n0 H$ f0 {7 q' I插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|