|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 * M1 H1 ]+ p" W2 o5 O
% ]! r' g4 t! ^. P
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
; |9 @& g, W; o( I
+ C% B3 @* S4 @0 i i我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了6 {5 s4 e9 U% f8 J
" z u/ Q/ Z Y3 w5 z5 p方便实用 简单 何乐而不用呢- - @9 t5 v2 ?6 I$ m! A; p* I0 |6 F
- <?php
4 n$ I j0 q- Z9 I! U+ h9 b9 g
/ L4 H+ u; @$ h- define( 'ABSPATH', dirname(__FILE__) . '/' );
& \0 f/ \ a- ? - require_once( ABSPATH . 'wp-config.php' );* c b; } U' A
- require_once( ABSPATH . 'wp-settings.php' );! o/ n6 Y4 b }5 V) @1 L. m
- require_once( ABSPATH . 'wp-includes/class-wp.php' );! z3 [! B! w' F$ u2 b6 |7 g3 |8 e
- require_once( ABSPATH . 'wp-includes/functions.php' );
1 E/ B/ C% e. ~' z1 M" O5 a" u - require_once( ABSPATH . 'wp-includes/plugin.php' );9 |* \0 @/ F% q& f5 R
- $title = $_POST["title"];. ]' N2 o' J" `; p# L( K" t3 ?
- $content = $_POST["content"];( x9 h' {: x6 p+ W a2 k
- $tags = explode("_",$_POST["tags"]);1 s- H5 \0 e0 G
- $cate = $_POST["cate"];' v8 @8 r0 J6 e
- //print_r $tags; j' a! R: B9 K4 w2 g
- //" |5 R; P% f# W& S; q/ a) N
- //% n+ |. q+ u# D& a: [) k/ h
- $wp = new WP();
5 V" K5 s6 |2 A. z - $wp->main();) M W) R+ |8 b b0 v4 ^
- //; `; D- K) x! M: M" O
- $my_post = array();. @9 y* L/ j3 G6 H5 K x; }
- $my_post['post_title'] = $title;" K+ T! ?* O" `+ B
- $my_post['post_content'] = $content;
7 B) {5 n* l/ P$ B - $my_post['post_status'] = 'publish';6 U0 W; a4 | C4 M! G
- $my_post['post_author'] = 1;# X8 c7 Z+ A) n& M7 Y2 q% Z
- $my_post['post_category'] = array($cate);
: N1 `! I- u3 D1 G* p& Z7 q' p - $my_post['tags_input'] = $tags;
c) w) m6 F0 Y& ]/ W9 Y, X - //$my_post['tags_input'] = array('tag1', 'tag2');1 Y) L5 T# B+ G. E7 ]+ C3 p
- //$my_post['post_status'] = 'future';, O8 w7 c& Q) s% c! c: U) H$ Y
- ////$my_post['post_date'] = '2010-07-04 16:20:03';- J! A5 t* L- L x4 q o7 C* h
; |( E+ k1 T" c; J3 L1 {; [- // Insert the post into the database
, g+ u$ U5 j( a$ x# m* x% f - $ret = wp_insert_post( $my_post );6 [( g! u" h! T2 _$ ]8 N
- echo $ret;
4 U. N: m$ g$ r( q. H# j - ?>7 M% n" `' r# k
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 7 Z% P" ?# J& r6 P
- <?php& t; r3 i4 E3 O# Q* E* M6 V- M
- define( 'ABSPATH', dirname(__FILE__) . '/' );
- k( R& g% J% _+ T1 c1 | ` - require_once( ABSPATH . 'wp-config.php' );
P# E2 x2 y4 c C( u8 e - require_once( ABSPATH . 'wp-settings.php' );& ~* |! x# X. E6 t6 v
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
. C3 R- e; m; Q) t - require_once( ABSPATH . 'wp-includes/functions.php' );
* p2 M+ d6 [( b - require_once( ABSPATH . 'wp-includes/plugin.php' );. n7 s5 B7 z8 J- \/ v" S
- $pic_name = $_POST["pic_name"];+ \5 C# U r- F7 u' X3 Z( W) c4 d
- $pic = $_POST["pic"];! Q/ v7 g* d, b3 l0 e$ Z
- if($pic != "" && $pic_name != "")
, r9 X3 b9 h- _* t) `. P - {
' D) G+ n9 } z; z3 O. u n - $path = "images/";
7 `0 t! ^' E o) @ \ - $pic_name = $path.$pic_name;
9 \ w8 ~% J. C4 J3 _) [ - echo $pic_name;
& o- z+ v) W/ o" Y$ K - echo "||";
7 m9 O# I# T1 [# R) j7 [3 S2 _6 V - error_reporting(0);) k7 @ E: e" j; Q) \+ v' m1 u3 k: }
- mkdir("images");
8 u8 h) O9 E* M, K. E5 f - $handle = fopen($pic_name, 'w'); ]" O: s2 s3 q" N
- echo fwrite($handle,file_get_contents($pic));5 P2 }% J0 u0 u T0 j3 A
- }3 `% E2 t4 f5 M: n; o' k# y0 R7 R
0 S3 [" z7 Z. d* y3 [+ x% p- $title = $_POST["title"];
1 m+ l1 h2 e+ `9 H( S5 s7 N - $content = $_POST["content"];
1 C. S6 `& u& B! D1 C/ Z - $tags = explode("_",$_POST["tags"]);
$ q% ?0 U0 h- C! f' L2 ~+ V* s - $cate = $_POST["cate"];
; A( Z% G2 e6 S) ?8 g" S - //print_r $tags;/ \6 W- z! t2 @' e
- //
5 p. f z" |' b1 P- s8 z3 [ - //# [# H6 h0 f1 w1 `. c
- $wp = new WP();2 G) y* u) [$ A- z# Q* Q1 H3 @
- $wp->main();, h) l) q4 M7 r! G
- // s. Y9 M5 O6 g
- $my_post = array();0 I$ X+ J M8 S- m# B
- $my_post['post_title'] = $title;
# K5 R7 ?; n9 A! | - $my_post['post_content'] = $content;& x: U" M6 @4 Z+ L2 C) T( M
- $my_post['post_status'] = 'publish';
$ p' q) j/ {5 h8 q; i1 y - $my_post['post_author'] = 1; b7 `% @) U& R+ D9 s" i8 E4 ^
- $my_post['post_category'] = array($cate);
' }$ `2 J. v3 w+ s! I - $my_post['tags_input'] = $tags;( p: x' m) ]3 J5 F
- //$my_post['tags_input'] = array('tag1', 'tag2');# b; b6 o1 c* P9 q) c
- //$my_post['post_status'] = 'future';
9 n- K" Q' H4 i+ c+ m' V! Z v - ////$my_post['post_date'] = '2010-07-04 16:20:03';
& ]& y6 z9 k' D7 c& K
) \5 S5 n( r, J/ k- // Insert the post into the database$ v$ N8 V; B- @0 ^" |5 a
- $ret = wp_insert_post( $my_post );; g( S$ h% y; A; q% m' Q2 W
- echo $ret;
* ^# R! c" J% G9 O2 O; N( w; p3 T - ?>
; n4 B' A4 a2 A; y+ U9 q# v( x
复制代码 我自己写的
$ Q! T1 l( { Z. d: g3 y插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|