|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
8 `4 F: p% G$ f
2 H, |* U N/ y9 a7 m- v0 Q直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持8 i% K( l6 d0 z2 X$ t* z8 q1 f
( n0 H; j* g( h1 o4 |7 {& W
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
) q& Q c% m4 J L ~% |; s& q( k! a9 ?
方便实用 简单 何乐而不用呢- & L+ {5 W& G" v& E
- <?php
" t9 V5 D1 |$ h7 } d
+ B, P2 Q7 j& N2 S% S5 H+ n% k1 Q7 X- define( 'ABSPATH', dirname(__FILE__) . '/' );) f \; n: h+ H) k, ]
- require_once( ABSPATH . 'wp-config.php' );
7 p. n4 _8 g [/ I. P, K a - require_once( ABSPATH . 'wp-settings.php' );
# R! b, K: o' F: i# t# h x! k - require_once( ABSPATH . 'wp-includes/class-wp.php' );
A3 E" c* Q* T" I( J; T- E - require_once( ABSPATH . 'wp-includes/functions.php' );
; u. M/ l% n* g8 y" l$ f - require_once( ABSPATH . 'wp-includes/plugin.php' );0 U) B9 k9 Q4 S# |6 V# S* s* o
- $title = $_POST["title"];
# F \3 W$ M0 L) a* v$ ~ - $content = $_POST["content"];
8 [0 y( ?! ]; n/ ], W y - $tags = explode("_",$_POST["tags"]);
) L% ?( a# d& |3 H/ G - $cate = $_POST["cate"];; Q7 s: \3 O3 ^$ J: f
- //print_r $tags;) e4 h9 c. a7 A" g1 N! @
- /// l9 [/ g: Z( l* }5 _: h: {
- //
0 O' p; q5 m6 p* X( I( a; o: \7 a' y - $wp = new WP();% D9 k# n; f% _ o$ _8 v
- $wp->main();
# P( ~, b0 k0 V/ Q - //
/ C' F( `; z ~) h7 c) K9 B- C - $my_post = array();
& R3 X/ Y$ B1 f0 m' g - $my_post['post_title'] = $title;9 a5 D& c/ o( X {, B
- $my_post['post_content'] = $content;3 n5 k0 S) B6 Z+ n: ?/ r' ]/ g' k4 e
- $my_post['post_status'] = 'publish';
0 D' g ~$ ^" @5 |$ q7 F z - $my_post['post_author'] = 1;5 V6 c; h0 t! {9 z) y
- $my_post['post_category'] = array($cate);
. ` a3 A9 c$ K0 u - $my_post['tags_input'] = $tags;7 O |9 H: ~0 @% a
- //$my_post['tags_input'] = array('tag1', 'tag2');
/ j/ W ]. W# z/ J, p- k - //$my_post['post_status'] = 'future';
1 m# H1 @0 T a) x, |! z' Q8 | - ////$my_post['post_date'] = '2010-07-04 16:20:03';+ s0 L8 Y7 `2 Y' M% M3 G
- 5 p6 b1 w+ b% k6 g2 i- c
- // Insert the post into the database5 d2 q ?. H( F0 K% W
- $ret = wp_insert_post( $my_post );3 _' g) x# n O" Y& W# D
- echo $ret;/ A t P4 C8 v& R
- ?>
5 F) I1 r( K' u2 d! y4 |7 [& l8 h% ]1 y
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
- _9 P6 S, V+ s9 F m- <?php! X4 b; O. g/ X5 z
- define( 'ABSPATH', dirname(__FILE__) . '/' );: k/ S- x( ^8 b; w1 [+ B
- require_once( ABSPATH . 'wp-config.php' );
* A6 v I- U \5 ~* M - require_once( ABSPATH . 'wp-settings.php' );2 Z6 T2 w# h4 g+ y: g2 K. ^
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
0 {* H4 [, Z* d3 u" C z$ Z - require_once( ABSPATH . 'wp-includes/functions.php' );0 {7 J' w+ c; ~. A
- require_once( ABSPATH . 'wp-includes/plugin.php' );
# n# v6 k4 D' }8 F7 q - $pic_name = $_POST["pic_name"];
* W* R/ E0 c2 R4 m! v* X3 Z9 L - $pic = $_POST["pic"];
4 h7 p- D+ S0 Y, H3 p% S: | - if($pic != "" && $pic_name != "")) \0 `; b. d5 O3 t; @: k, a0 Z
- {
5 V; [0 ]% i8 r7 G. R4 y. A - $path = "images/";7 v8 u% c* X0 P
- $pic_name = $path.$pic_name;
" s/ C4 _/ j0 t1 w5 U - echo $pic_name;
# Q, Y* [8 n# b/ t7 T& ? - echo "||"; J$ `! Y0 {* p1 A9 Y1 U7 N- w
- error_reporting(0);& }, @' ]# q) P! J% C
- mkdir("images"); W7 P! l0 A) Z3 `$ P4 t1 i2 g
- $handle = fopen($pic_name, 'w');( Y7 \1 S2 p# y& `) }
- echo fwrite($handle,file_get_contents($pic));% [3 O& t9 Q+ y# l
- }; {4 o! L" l0 G# M+ a' S/ h
7 l6 p# e* s ]2 r: {- $title = $_POST["title"];
) h& U/ z; L7 p0 G; o - $content = $_POST["content"];8 E$ s( P; ` g
- $tags = explode("_",$_POST["tags"]);6 `& S6 q0 q! q8 n4 E5 q2 h; I
- $cate = $_POST["cate"]; K" j) L/ i6 j- F1 P
- //print_r $tags;
1 a3 o+ H# l) s: v - //
5 x9 P$ B% e3 o3 I' _) @ - //: M0 S* L3 s0 g2 e% ?: ~
- $wp = new WP();# p& s# q+ C* `& |. k4 g& o
- $wp->main();
! y# o4 s% `3 a. }5 H& {, L - //5 c; q" G- n( M) O2 ?
- $my_post = array();( E4 z5 P2 y. o) ]& N
- $my_post['post_title'] = $title;
1 h. s. z, y5 k$ O - $my_post['post_content'] = $content;
& ]( }& v* a' C- S! k - $my_post['post_status'] = 'publish';5 r$ x3 Z1 w2 Y4 n) C5 v
- $my_post['post_author'] = 1;3 T2 T( n2 A/ f( q" r3 ^) P6 z% _
- $my_post['post_category'] = array($cate);: s3 T8 W$ Z9 F3 X/ ]( y6 h
- $my_post['tags_input'] = $tags;
# f' a2 I. g) t, s* c. v! s - //$my_post['tags_input'] = array('tag1', 'tag2');
O5 k5 ?, i# |* l - //$my_post['post_status'] = 'future';
$ N. c6 | W \! w' S4 U+ V' J - ////$my_post['post_date'] = '2010-07-04 16:20:03'; G7 L# z/ h( J E2 p2 ], R
- 5 @# ~/ y: L ~: B$ M" ~. H
- // Insert the post into the database+ l' f& B9 q X' }2 i2 [
- $ret = wp_insert_post( $my_post );/ A! _3 b" @9 S
- echo $ret;
+ j' D+ P0 R5 } s+ v$ n- h - ?>6 |& J! W; h& p9 g6 c
复制代码 我自己写的
1 h" x4 ]) I! k插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|