|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
& z2 T+ V7 ]9 N) Q% _8 {" Y- u! ^, h& N8 [' m+ k5 I; I( D
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持5 X! u# [3 P# d
% }8 \: l2 m& q' T
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了4 w9 u2 L" f- ^$ B/ L4 P
& X; s! u' @2 X2 C
方便实用 简单 何乐而不用呢- 1 l. g# Z$ z! w3 \( h3 E4 k5 R' ~$ `
- <?php
/ W9 E6 K* K# e& q. x' M - 1 p- D9 a3 k% |$ M& H7 G
- define( 'ABSPATH', dirname(__FILE__) . '/' );" S+ M4 w, O. J& c; c/ @
- require_once( ABSPATH . 'wp-config.php' );2 L. F8 k6 e8 ]" k) H2 ~
- require_once( ABSPATH . 'wp-settings.php' );
# ]4 [9 o/ B1 J ]$ L3 ]6 a( { - require_once( ABSPATH . 'wp-includes/class-wp.php' );
E a, p; c. E6 S: f6 c. R - require_once( ABSPATH . 'wp-includes/functions.php' );
' z7 l, F5 g- C- Z7 b9 l1 Q - require_once( ABSPATH . 'wp-includes/plugin.php' );8 ?4 P9 e5 T( C
- $title = $_POST["title"];# [6 h. P6 Z9 @$ X; B; y+ ?& n% p
- $content = $_POST["content"];
; @3 c) a, A* j) r - $tags = explode("_",$_POST["tags"]);
4 [5 G) |" `" f9 `4 b z" L4 N - $cate = $_POST["cate"];, [! z6 ]& E9 U* D! e3 E7 P
- //print_r $tags;6 e8 R4 l" ?; W
- //
S' b! ^- ]- ^+ U& j5 }6 i$ o$ w - //
5 C1 y* x! J9 _2 [% G% @7 Q* q# U - $wp = new WP();
/ G: f7 t: T3 ] - $wp->main();2 @2 C0 m0 F' n( o
- //
8 F1 O! Y1 q, u; ^' r0 ^ - $my_post = array();
6 E1 B1 X( Q( g+ m* f; X - $my_post['post_title'] = $title;
, D5 w6 M5 M& P3 a - $my_post['post_content'] = $content;9 {. C5 a& d' Q
- $my_post['post_status'] = 'publish'; U# }9 l' h7 f# ^4 g
- $my_post['post_author'] = 1;
: |7 [$ H+ f( d0 B - $my_post['post_category'] = array($cate);/ v$ I1 _$ r; h
- $my_post['tags_input'] = $tags;9 K+ x7 k' r+ y! _& A9 }8 U7 [
- //$my_post['tags_input'] = array('tag1', 'tag2');3 N7 e0 \6 {! t( \% a! I- f
- //$my_post['post_status'] = 'future';
! N8 O; y) x4 e0 a' c6 { - ////$my_post['post_date'] = '2010-07-04 16:20:03';! J. m2 W) q! \$ _0 g" u- s
5 `; Y/ e# X8 _/ y) E" o- // Insert the post into the database
) ?8 g5 E4 P/ d) e8 \ - $ret = wp_insert_post( $my_post );
" i" g" c& ~6 h& A K+ \/ y/ p - echo $ret;
* X* M: o: s( L" S4 s - ?>% p8 i* E1 M- Y, q& }4 I7 e: s
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
, |8 `' m, a4 J. B2 u+ H- N- <?php
8 g' w/ H. |4 ]) L: l - define( 'ABSPATH', dirname(__FILE__) . '/' );; C# a5 `8 v8 x: [3 v: A* b
- require_once( ABSPATH . 'wp-config.php' );. q! K+ W+ t8 H. Q+ o% G
- require_once( ABSPATH . 'wp-settings.php' );: m6 f4 [& J1 }+ D0 g% o/ |, B* s
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
5 E4 f- W* F3 h - require_once( ABSPATH . 'wp-includes/functions.php' );* h( n' [" T( B
- require_once( ABSPATH . 'wp-includes/plugin.php' );- f' F- ^- f% e' Q7 Z
- $pic_name = $_POST["pic_name"];8 }' I, ]" h- |* l$ @9 U9 r
- $pic = $_POST["pic"];
0 I" n; A8 w7 d* }) \, R - if($pic != "" && $pic_name != "")' y3 `7 L$ `+ K1 ~/ k4 O; b
- {! `; a! Y- q6 s- f. y# N7 n% S
- $path = "images/";- N% L) v/ o$ [4 d; ?
- $pic_name = $path.$pic_name;
8 [& L4 [/ m/ D$ n8 K: z - echo $pic_name;$ E1 N" l+ B0 G5 g6 `% C$ ~
- echo "||";
( z& w3 e; j& [, L - error_reporting(0);/ {! q+ ]; E* E( y
- mkdir("images");
9 K2 w4 _6 r6 q- a6 c1 U - $handle = fopen($pic_name, 'w');8 s. r0 t; N4 `' V+ M6 \8 t# {
- echo fwrite($handle,file_get_contents($pic));, G+ E& ?5 W$ r7 d. L! `5 t" [3 S
- }
" |6 ]1 P6 m- s# F, {+ S( D6 @ - & E, T; U/ w6 k3 R+ i/ B- _7 b
- $title = $_POST["title"];
- z0 k+ j- z# R$ H4 L6 }& Y$ q - $content = $_POST["content"];) n; m$ p* [/ T: c6 l- J
- $tags = explode("_",$_POST["tags"]);
+ `# W! H: Z# g- r2 { - $cate = $_POST["cate"];" r0 l0 y/ ?+ `
- //print_r $tags;9 C& u1 L" f/ x! k; j7 i# L6 k
- //
9 ?9 [; X; V8 w- F. A6 ~7 ^0 I - //
) N) Q/ M0 o1 I8 q; O) U - $wp = new WP();
2 Y( H4 V+ D0 B+ u - $wp->main();
4 E- f+ o, b! }! O" s, [ - //
7 _, y- G2 U3 m; |$ Y+ S0 k - $my_post = array();8 F: p" M- v, n/ L7 c
- $my_post['post_title'] = $title;
8 U0 C1 ^' ? {$ _) O0 g+ S7 v! E - $my_post['post_content'] = $content;! y p2 f+ e) H# ?' w
- $my_post['post_status'] = 'publish';, w* V& H6 Y: T$ _! K
- $my_post['post_author'] = 1;
7 i2 S4 w: Q @ - $my_post['post_category'] = array($cate);! r+ O2 n7 ?0 l5 b% _: G u1 N
- $my_post['tags_input'] = $tags;* Q% [/ w+ c8 p
- //$my_post['tags_input'] = array('tag1', 'tag2');9 Y# t. O. o( d0 k5 N5 S
- //$my_post['post_status'] = 'future';$ v/ i1 b. u5 `+ E
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
; B+ _1 q/ ]. O' S
0 [0 ?- H2 z6 l; d9 X4 _ l# {- // Insert the post into the database' A6 z6 V& K# N( t3 N9 A
- $ret = wp_insert_post( $my_post );
" X* g0 X0 ]4 E) Q& J - echo $ret;( v; ?9 f( W* k7 @; ~
- ?>
6 V& \# o" S4 o. ^
复制代码 我自己写的
3 m' {( Q$ ~0 w5 p( |插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|