|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
2 R; v" W7 U* [# Y( W1 D2 A+ R- {& [) W) M) V
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
1 R' p( i" p3 C" _1 p6 p5 H% ~0 W: E8 X6 _
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了: {* K" s5 K p2 y& ^
. I. c* E& T) U! | _
方便实用 简单 何乐而不用呢
, |, X" { a* E- <?php- q8 R* d; a/ \! ]- {' _
. ]7 y9 [4 J0 J4 Q% t- define( 'ABSPATH', dirname(__FILE__) . '/' );. U+ K5 ?# K! a) Q4 j
- require_once( ABSPATH . 'wp-config.php' );$ U9 H2 M$ m3 m0 _8 y& V( L) f& S
- require_once( ABSPATH . 'wp-settings.php' );1 {: @$ u9 {1 E, w
- require_once( ABSPATH . 'wp-includes/class-wp.php' );# A* y" y8 o$ U9 ~' q
- require_once( ABSPATH . 'wp-includes/functions.php' );5 z8 Y3 I4 @) t1 T+ S& T
- require_once( ABSPATH . 'wp-includes/plugin.php' );
: G9 v4 O' W2 l% }8 V; G, L9 e - $title = $_POST["title"];
# L0 t; k. M5 h& ? - $content = $_POST["content"];0 m2 h( y( j' {8 i2 s2 u3 c
- $tags = explode("_",$_POST["tags"]);/ D P- H t) i/ h
- $cate = $_POST["cate"];
- W& A- d9 F& ^; l# i) _3 ~$ O - //print_r $tags;
; f0 j9 m) k6 k8 T0 k, u& e) T - //$ }* u" W: p1 b$ Z, E$ ~8 ^
- //
- l9 v! B+ X' v2 M - $wp = new WP();- t9 a3 ]1 ^1 i3 A
- $wp->main();
, @/ f* G/ c) r9 @- m8 o - //
9 u) j6 s+ Z' \. f$ A, `. U2 F - $my_post = array();; x) e. {* c; c4 h& s6 s4 Y. \7 B
- $my_post['post_title'] = $title;' i0 `6 C0 d4 Q- Q- {3 J
- $my_post['post_content'] = $content;
5 l4 k( ?% ^ s; O/ s4 n - $my_post['post_status'] = 'publish';$ H X3 Z" y) X' G
- $my_post['post_author'] = 1;
& F& H' _# H, Z+ J* k( O- [ - $my_post['post_category'] = array($cate);' W$ g# ]. c+ ~% p2 c
- $my_post['tags_input'] = $tags;7 h: l7 T2 W: c6 c
- //$my_post['tags_input'] = array('tag1', 'tag2');
! v5 J7 I+ j7 w& h, g% ] - //$my_post['post_status'] = 'future';
1 J6 q" }5 C) {2 I' T - ////$my_post['post_date'] = '2010-07-04 16:20:03';
3 A- ]" z. v' b: ^
& f- K6 a+ s/ n* c+ \, @0 @2 A- // Insert the post into the database8 o- h4 i" y& o3 A: W) V
- $ret = wp_insert_post( $my_post );$ S6 g& C2 E* Q& n3 z
- echo $ret;) I2 d8 y. f% o- L; t
- ?>
, C/ y: n- Y. D9 x# N( d3 G
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
- f1 R W: N6 a; a6 D) d& \- <?php
/ e) ]* X1 \0 W" s - define( 'ABSPATH', dirname(__FILE__) . '/' );
; e5 m1 E/ d i0 @) B' X - require_once( ABSPATH . 'wp-config.php' );+ L1 ~0 ?2 Z) g; P4 i* K
- require_once( ABSPATH . 'wp-settings.php' );
/ a* K# v3 j7 y& H3 @ - require_once( ABSPATH . 'wp-includes/class-wp.php' );
' K8 Y6 e2 P/ }8 K$ _ - require_once( ABSPATH . 'wp-includes/functions.php' );9 q3 z9 J7 j0 Y
- require_once( ABSPATH . 'wp-includes/plugin.php' );' f' T6 L) J; \+ [
- $pic_name = $_POST["pic_name"];3 G" o) p+ h0 Y" [
- $pic = $_POST["pic"];
. J! G' w& [- L2 P3 p$ [7 m - if($pic != "" && $pic_name != "")
2 ^- {" T8 u" I2 i6 e& K. m4 u - {
- c/ L% F4 }' o9 A8 _, o E6 B - $path = "images/";
. g3 J% Y: O! v- q" G8 B - $pic_name = $path.$pic_name;
: z3 m$ V: h% ^8 m - echo $pic_name;
' j- N+ _0 k2 J/ `8 c - echo "||";. x2 u6 d; g I" D
- error_reporting(0);
7 ^2 T* H; X) h. `( N( x+ V9 H' A - mkdir("images"); i! K; g! r/ L% K
- $handle = fopen($pic_name, 'w');6 \' S' l5 k- F% Q+ b% x
- echo fwrite($handle,file_get_contents($pic));8 E# n$ ?$ T8 t) ^/ S8 l/ z( {8 A( a9 I
- }
2 l4 ]) M' o! ^$ m1 B - * ~+ j5 h* O0 D) Q8 |) x- k
- $title = $_POST["title"];) J" U" t* m: P9 P2 Z$ z
- $content = $_POST["content"];
) p6 s7 }; G; ^9 O) S4 X - $tags = explode("_",$_POST["tags"]);
! V! c* L5 P" s m - $cate = $_POST["cate"];( h+ [; p9 n4 L8 I
- //print_r $tags;: P- L, ?8 l7 p6 P. Z* z7 n5 u
- //
* c$ K" W d) | - //- p- a" i V6 q2 }' ?2 I8 d
- $wp = new WP();
" ]( Y" {% e: u% y; }1 F: G - $wp->main();4 V7 T6 f9 `7 A* d2 |$ W" m
- //# L& r; p* Q7 @3 n8 t2 o& I6 A
- $my_post = array();
9 S, {" ?! J$ ?1 X0 H2 l - $my_post['post_title'] = $title;
$ h& P& `% V4 G3 r7 A) q- [$ N* P - $my_post['post_content'] = $content;; K, l& F1 X/ k" w
- $my_post['post_status'] = 'publish';8 z) v" R" }+ Q$ `: b. }
- $my_post['post_author'] = 1;
5 g- h2 ?; M6 ^' l - $my_post['post_category'] = array($cate);; r( \# r: s1 X) N& ]8 T
- $my_post['tags_input'] = $tags;
E9 Y T# N+ R' G( z3 P) J/ p - //$my_post['tags_input'] = array('tag1', 'tag2');
- \7 Q/ H6 E3 G7 X7 U. ^ - //$my_post['post_status'] = 'future';
' d' |- r+ k" X5 | o, A - ////$my_post['post_date'] = '2010-07-04 16:20:03';1 P1 F1 x+ {. \( C! X
- , p0 y+ p, X4 x9 a; s: l- f9 Q- I
- // Insert the post into the database
* Z9 m2 d% j+ g( b: I5 h, A5 D - $ret = wp_insert_post( $my_post );
8 a6 C2 [. x) w/ J, M9 R: l+ i - echo $ret;
8 ]/ V( ^2 G" `: P8 s& n - ?>
, Y5 C/ ]5 S8 j# z' Z' d2 Z
复制代码 我自己写的! V4 {2 ~; [' d* u+ i1 R+ `
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|