|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 : J/ K) b2 x# c9 S
2 B6 o- K2 I; x% R. M. ]. Q' y直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
6 J6 t, F: c$ D) C+ W$ _1 \ i+ G1 B6 P) Y$ }1 f( B
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了( q" r1 R6 E, p4 ^2 m) `
' Y; J- o8 s- l3 _
方便实用 简单 何乐而不用呢- * ]* l/ o2 Y( t: E* m8 o3 n! x
- <?php0 I' _' e! l4 [& q
" i9 G$ G! m- s6 B9 f) M9 G- define( 'ABSPATH', dirname(__FILE__) . '/' );
7 Y9 H1 c8 F/ D9 D- L - require_once( ABSPATH . 'wp-config.php' );
! B: T/ T0 ~& H5 Y& |( P3 ? - require_once( ABSPATH . 'wp-settings.php' );8 H3 ?+ C$ c' K( K Z- U; M6 `
- require_once( ABSPATH . 'wp-includes/class-wp.php' );- h& w! [( b# G" E$ _ K. E( x
- require_once( ABSPATH . 'wp-includes/functions.php' );
7 S' k; }' c, ?; `' k - require_once( ABSPATH . 'wp-includes/plugin.php' );
1 M/ u9 J3 I9 T7 M& ? - $title = $_POST["title"];; x. q& d X, m, {: y1 d( H, R
- $content = $_POST["content"];" \6 Q5 @& T; _# ~( r
- $tags = explode("_",$_POST["tags"]);4 F0 {0 A) S6 N9 V! K
- $cate = $_POST["cate"];
4 I+ p) B8 X3 J; x9 w8 V - //print_r $tags;
5 \6 k4 p; f1 K' Q! a3 S' W3 r% P2 F - //# o! O5 k# i" l3 [
- //% k1 S9 o& m0 j. i! ^
- $wp = new WP();
, Q% n# z1 f/ P9 }" C8 r - $wp->main();
, ^, L V* S- h+ W - //
2 _0 K5 {: J( [ - $my_post = array();
/ @) l4 ?# ^7 {1 f - $my_post['post_title'] = $title;5 o3 T3 v7 I6 S r1 E! U( \
- $my_post['post_content'] = $content;6 J% q8 W& P7 b2 C9 E
- $my_post['post_status'] = 'publish';2 p+ M, H; c3 y( I
- $my_post['post_author'] = 1;/ }) q$ y& r$ O7 U
- $my_post['post_category'] = array($cate);
4 E, n3 W# {0 j - $my_post['tags_input'] = $tags;5 W$ Y: m( J0 g) @% J
- //$my_post['tags_input'] = array('tag1', 'tag2');
. ]4 f" G) X9 C/ v - //$my_post['post_status'] = 'future';. M6 Z! ]3 m7 R! K/ g: S/ o& o
- ////$my_post['post_date'] = '2010-07-04 16:20:03';8 H& X6 ?) `4 I. n
! }) w& J* J" q% N: k- // Insert the post into the database& i5 ?0 [; O$ e+ Y/ i I
- $ret = wp_insert_post( $my_post );
( W' W. A! D, O7 ]9 ~ L - echo $ret;
' S' k" x+ ~ {7 q5 M$ |. y - ?>
8 k; Y1 W0 M0 g5 e6 J
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
1 c% v, `; V2 P2 G$ ~- <?php# ]! J1 v( [ \7 w
- define( 'ABSPATH', dirname(__FILE__) . '/' );
( B3 P. K& O3 p# Q. d9 N - require_once( ABSPATH . 'wp-config.php' );7 b+ o. U* P$ K
- require_once( ABSPATH . 'wp-settings.php' );! s* u4 v' [; Q5 t5 S" S7 d
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
% p8 |7 o" H9 y, X - require_once( ABSPATH . 'wp-includes/functions.php' );$ T# P+ w0 ^2 J |& W
- require_once( ABSPATH . 'wp-includes/plugin.php' );9 |5 C7 t- D# l( h- Y
- $pic_name = $_POST["pic_name"];' I5 T" l9 W. l! j9 a8 l( y
- $pic = $_POST["pic"];- S: @7 p+ C$ |. q
- if($pic != "" && $pic_name != "")# t3 x) _" Z8 E2 b+ O+ P5 o4 o
- {! s0 i: `9 D. r0 \& D2 p
- $path = "images/";
$ R3 P& R2 l1 b# w6 v - $pic_name = $path.$pic_name;
- r" f# J0 ~( n0 E" t - echo $pic_name;+ y( @6 N1 T* W/ ~) }
- echo "||";8 ^% w; ~" J# ]; d; w" M
- error_reporting(0);* J: z: }) Z9 T* S$ v Q
- mkdir("images");
7 ~4 q9 {) Q) r( ?* J0 D - $handle = fopen($pic_name, 'w');
' `, F4 \( A# @# N - echo fwrite($handle,file_get_contents($pic));! X8 n, `5 \5 M- \; K1 S
- }6 i2 e* a( d! L$ _3 Z* [# Z. K3 a" i
, S5 K' J- S% r* A2 R- $title = $_POST["title"];
2 c% Z: o1 x% X% e1 S0 i0 J - $content = $_POST["content"];( j' J1 n$ w. P: x0 u& U
- $tags = explode("_",$_POST["tags"]);+ X4 p+ A) \+ n/ y& W9 |4 W+ D" q: t
- $cate = $_POST["cate"];
1 u8 P G' r4 q$ ^$ \$ d4 V - //print_r $tags;. ~ d1 v4 G. `9 V: h
- //
& y, J! m" ~: w; q9 P - /// I* J4 K; m# {/ u) S/ c0 e
- $wp = new WP();
! d6 K0 v+ w6 b. a$ u - $wp->main(); ?8 N* G5 F# _# b7 p. N* [
- //
& @3 b3 f3 s# p4 H# L0 j - $my_post = array();
- h$ K E6 _& E3 g3 J+ ` P3 W; Z+ l - $my_post['post_title'] = $title;
q+ A0 o/ q: A$ F8 D' C - $my_post['post_content'] = $content;
1 r! ]1 o/ h9 y - $my_post['post_status'] = 'publish';
- r% W- y4 O" m' @% o& h - $my_post['post_author'] = 1;4 K" i# W* r) e Y4 G" [
- $my_post['post_category'] = array($cate);0 Y, P) L' k7 S: q
- $my_post['tags_input'] = $tags;8 b% n! _6 e- J" S9 n' t
- //$my_post['tags_input'] = array('tag1', 'tag2');
4 S! Y* D: Q: u - //$my_post['post_status'] = 'future';
$ v7 d# s0 J4 f0 n - ////$my_post['post_date'] = '2010-07-04 16:20:03';
4 M9 ^" g; U4 f. N$ k: S6 H# i
0 ^ Q8 D4 k$ t- // Insert the post into the database
* O z: L2 E, \7 b - $ret = wp_insert_post( $my_post );
& @: f( a, y |, C - echo $ret;
& p/ V; _" h" \+ j - ?>, }* p; e* v* V- w( d* E
复制代码 我自己写的+ k6 }4 x! D f( O' a) w/ M$ o
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|