|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 ; r- [& w: Y3 ~! x1 O
0 ?, b* Y, z6 {
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
3 y% x4 b2 _% W5 I3 B: d6 a8 U! k- t8 f, a
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了" D$ F" r1 {( J: |; z" f" z
2 z9 [* c8 U0 [" g8 Y8 t$ l3 {% H方便实用 简单 何乐而不用呢
4 o" G% ]8 d2 @ x- <?php
, B* r$ T; y8 W. M+ ]
% J I1 [8 F; d0 K: ~6 n; w- define( 'ABSPATH', dirname(__FILE__) . '/' );; E n0 A# w; Q# `- `3 G& d
- require_once( ABSPATH . 'wp-config.php' );0 ]/ b* @. ?3 ?5 M; z4 ~; Y0 F
- require_once( ABSPATH . 'wp-settings.php' );
9 a! W B* V+ q3 |) q - require_once( ABSPATH . 'wp-includes/class-wp.php' );: B# G! c: {" @* c5 s& ~" O8 K
- require_once( ABSPATH . 'wp-includes/functions.php' );
# j2 x4 F! t+ r1 K - require_once( ABSPATH . 'wp-includes/plugin.php' );/ D( L K. e/ A9 W. w
- $title = $_POST["title"];
% c$ V ~" [' K1 P) M: a1 o - $content = $_POST["content"];; ]6 x3 m, a. G/ U4 V- B$ V
- $tags = explode("_",$_POST["tags"]);
" G( R5 t: m7 n, B$ Z - $cate = $_POST["cate"];; a6 T7 U- [4 L. ]7 n
- //print_r $tags;9 r2 G }- D) \0 ^4 y' U& n
- //
8 x# X" x9 o; I0 v - //
5 _5 Q: W8 q8 a5 q0 p$ F - $wp = new WP();1 c/ U+ `% n# Z$ M% T
- $wp->main();
- z: M( l$ R, D# V- O9 g' W - //
+ [* B$ @" e7 o3 A# Y" c: e - $my_post = array();
" J! G4 Z2 w. ~" F9 c# l - $my_post['post_title'] = $title;% Q& b$ ]" @9 U7 l" V! U: @* u
- $my_post['post_content'] = $content;
# S, w! Q# P- J& Q& Q- Z R; [ - $my_post['post_status'] = 'publish';4 s+ @( s( L' T) Y( w! }3 q
- $my_post['post_author'] = 1;3 m6 _6 k8 i. e( h% L
- $my_post['post_category'] = array($cate);9 }5 @8 a7 _! R+ ?/ b! j
- $my_post['tags_input'] = $tags;: h% s& ~8 N( g: }" j
- //$my_post['tags_input'] = array('tag1', 'tag2');" F! [- T6 a. ?) F" `* W
- //$my_post['post_status'] = 'future';
7 j( S3 z2 u1 c$ E - ////$my_post['post_date'] = '2010-07-04 16:20:03';1 D( M( \% m% Y& y. Q
- ' ^/ ~7 | ]9 A; N
- // Insert the post into the database; t: o8 W1 f4 h- i p! B* v [
- $ret = wp_insert_post( $my_post );
% D. ]4 F, t3 b# | k' _1 [ - echo $ret;1 v0 U0 \0 a; S& y
- ?>
" j! }7 |6 w* j- E: V& i$ C2 d
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
5 k0 U4 ?, Y6 o7 Z- <?php
. f: _3 E+ ~3 ?5 D; P# k - define( 'ABSPATH', dirname(__FILE__) . '/' );
( T$ M3 Z$ h2 [& X( m4 ^2 r8 n - require_once( ABSPATH . 'wp-config.php' );
`0 ]' U3 Z# N3 m$ _/ b. ~ - require_once( ABSPATH . 'wp-settings.php' );
F! f- v$ L1 |% M' ^ - require_once( ABSPATH . 'wp-includes/class-wp.php' );
; R4 n4 W3 k( e1 V. |* u. @ - require_once( ABSPATH . 'wp-includes/functions.php' );
_! P. F4 Q7 u" ? - require_once( ABSPATH . 'wp-includes/plugin.php' );* y4 H# b# i4 U. ]
- $pic_name = $_POST["pic_name"];, f- A5 @8 b1 J5 K& A# E4 D: B
- $pic = $_POST["pic"];
7 c" C3 e! D- l. s- N$ T - if($pic != "" && $pic_name != "")* X0 U& a4 o+ E. B
- {
* z6 v5 J6 X5 g Q - $path = "images/";% n& S: D; D& L5 V! L
- $pic_name = $path.$pic_name;
( o4 O$ k. d( A$ T+ @7 r - echo $pic_name;
' }( A f# r) {# R! u: H" p6 h - echo "||";
, O5 G. j; j* p2 z3 c - error_reporting(0);
' A l' `! Y( K6 K3 L$ x - mkdir("images");
?6 h2 r( n; k% ?) ~5 |, A: d - $handle = fopen($pic_name, 'w');
' d: u0 |) P0 Y+ r/ m% e! _ - echo fwrite($handle,file_get_contents($pic));
& D( w0 C) X7 ^) Z! Q0 I7 K1 M - }. z, g f- y8 }% P% Y
. t5 \! ^4 e3 s5 E V3 R- $title = $_POST["title"];. @8 N# v8 X" y7 r) S# m3 D% k
- $content = $_POST["content"];
7 A) |* E6 o I# A - $tags = explode("_",$_POST["tags"]);
$ a ^* o% ^% c: ^+ u/ U: [" ~) m0 l - $cate = $_POST["cate"];) ?8 g+ H$ ]7 L! T; C$ A
- //print_r $tags;6 \% }8 ~( J/ Q3 v. M9 z
- //
1 j7 `% d% T, ?( l. `* |3 L - //
5 n) l% Q, a! o, A9 E- C } - $wp = new WP();
1 e8 I; Q! O1 E$ N/ e) S) {( N - $wp->main();9 ] t- Q, u" q5 l$ V
- //
* L& _% ~2 v' a: f( y2 w1 J- n. [ - $my_post = array();* \2 H9 l. W9 D E1 m; V- d
- $my_post['post_title'] = $title;
2 b$ J4 B/ w9 }1 n+ s9 c - $my_post['post_content'] = $content;0 |) h# D! b7 n o
- $my_post['post_status'] = 'publish';+ T- q+ a9 |& l
- $my_post['post_author'] = 1;/ L. r! i3 w9 N. [
- $my_post['post_category'] = array($cate);
4 d5 m2 x2 p D3 t9 V/ t e - $my_post['tags_input'] = $tags;% J5 [. F. `) `3 a8 F4 Z
- //$my_post['tags_input'] = array('tag1', 'tag2');0 q" [: B) E% \0 f) |6 M
- //$my_post['post_status'] = 'future';5 o; C( s+ D4 O# g2 m4 @. @
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
; e$ m* g6 m. D5 B4 e# C
1 m+ s# V1 A& W' K- // Insert the post into the database i, ]- }$ @0 Y
- $ret = wp_insert_post( $my_post );
* N @% o# M3 {/ Z; M - echo $ret;
, y6 w9 ]6 F+ f7 Q+ } - ?>
0 _) h- M b7 N
复制代码 我自己写的5 J2 _9 u' p, u, C
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|