|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 3 E' ~% G1 r% W# a/ K: C
8 | f% \6 |$ E& ?$ S3 X# e r
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持* `- w5 N$ w5 {. Q0 ]8 c/ J. }2 x$ l
" {. {& g' z+ @* L
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了& x/ J6 a; N( ^! A9 W
; ~7 f5 _5 Z# m& _: k' [4 O3 }5 G' _方便实用 简单 何乐而不用呢
% O5 O2 [$ Q6 l/ p6 o/ L- <?php3 V" q( L" ~ c! a7 s$ Z
: T; N t! g% P- define( 'ABSPATH', dirname(__FILE__) . '/' );
7 y! T+ v/ ^+ F& z, M2 K9 d. t- E - require_once( ABSPATH . 'wp-config.php' );4 P$ Q; M3 f7 ^* z" }# ~1 U0 }
- require_once( ABSPATH . 'wp-settings.php' );
% Q6 |$ |0 D1 V8 n - require_once( ABSPATH . 'wp-includes/class-wp.php' );
B5 v1 s7 B# W8 Q6 x& h8 K3 }' Y - require_once( ABSPATH . 'wp-includes/functions.php' );/ M* z! r/ r ~7 V
- require_once( ABSPATH . 'wp-includes/plugin.php' );
$ ]2 Y6 N$ O* n6 S; q - $title = $_POST["title"];
- p7 g; [, S2 C {/ i$ D - $content = $_POST["content"];2 W3 Q; s# ]& W7 [, E1 B
- $tags = explode("_",$_POST["tags"]);
% m& z" ?/ ~& m" G4 t - $cate = $_POST["cate"];
, X, \! L' u* d& E - //print_r $tags;" F* H3 Y1 ^, D( z }- [- U& H
- //' e' d+ S8 L; U8 Q0 C3 }, F7 v
- //
, l9 S6 a1 T; I) ^6 { - $wp = new WP();$ i0 X9 B, s, X
- $wp->main();
9 K$ n) D: T9 h% Y5 y | - //- D0 I" E+ u. K( ~- x2 O
- $my_post = array();9 ?7 P0 B. i$ E, H- ~# B
- $my_post['post_title'] = $title;
+ B) F9 K$ O5 _ - $my_post['post_content'] = $content;
( d* X* z6 I/ X0 d- ?0 d+ a - $my_post['post_status'] = 'publish';9 C: D C- n. _
- $my_post['post_author'] = 1;
3 s. d6 r3 e4 x6 O8 ~ - $my_post['post_category'] = array($cate);
' p* u" t$ m/ d - $my_post['tags_input'] = $tags;8 ^- F# f9 I8 q+ |, j
- //$my_post['tags_input'] = array('tag1', 'tag2');+ Q* s5 K# `1 [: `
- //$my_post['post_status'] = 'future';# V0 g. M4 E0 ?' J- n; ^1 j( o) |
- ////$my_post['post_date'] = '2010-07-04 16:20:03';4 ^! E8 ~4 @$ u9 {! M
- 2 I1 m- V3 B, |( ?8 Z6 Q/ F
- // Insert the post into the database
" Q& S& R' w5 s' W! K# h - $ret = wp_insert_post( $my_post );
# o! b9 C1 S3 ?' r Y" `4 _# Q - echo $ret;
# F$ M, u2 N' ]& m: o0 y - ?>* Z; y- f, ]$ W4 L$ B- X a3 E
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- ( Y' W: R9 s! o) u
- <?php1 ~1 e- z) U( g R1 \8 ~; E8 [4 N
- define( 'ABSPATH', dirname(__FILE__) . '/' );9 A: \& l# H* p8 H( z, p( y O
- require_once( ABSPATH . 'wp-config.php' );
3 o3 f) d2 y! y9 \+ T- W- n - require_once( ABSPATH . 'wp-settings.php' );; E$ B' _+ t& l7 [- [/ [3 z
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
0 P3 m: ^, u j- ^ w - require_once( ABSPATH . 'wp-includes/functions.php' );
: Q" S0 X( q+ X1 ~, G - require_once( ABSPATH . 'wp-includes/plugin.php' );
' K/ w5 C7 P/ Y r0 ~' E - $pic_name = $_POST["pic_name"];# s$ ]0 X9 v& |+ W
- $pic = $_POST["pic"];$ [$ z4 m5 u3 @& G+ }7 ^( O
- if($pic != "" && $pic_name != "")
# P; ^' j9 G4 _8 j8 s" l6 _ - {
2 v3 O* ^, E# w& k - $path = "images/";
3 Z" Y4 j& D, e - $pic_name = $path.$pic_name;
/ M5 c( p3 W$ ~+ [ - echo $pic_name;! y5 f3 S2 G% r; H' R& D
- echo "||";
" M" e, w' r4 O - error_reporting(0);
$ i+ c& @5 E0 p) z. F - mkdir("images");/ ` M% f1 F$ l1 H+ R
- $handle = fopen($pic_name, 'w'); H( ^9 c4 P, y
- echo fwrite($handle,file_get_contents($pic)); ?8 M ]2 d r, K9 h
- }
/ g- H! r2 s+ M5 }) k* h* q G - 4 T- P& i9 d$ C4 h+ t4 e- [6 c C, X
- $title = $_POST["title"];
' q2 W0 g& }. z - $content = $_POST["content"]; b" Y* G8 h. P/ R9 s; y
- $tags = explode("_",$_POST["tags"]);3 ~" r- b; [' c5 `% j/ Z3 e: f
- $cate = $_POST["cate"];) F3 |5 N$ |9 X$ c- ~) l+ @
- //print_r $tags;% N" z* ]# C' q& l) c7 B
- //
% C' ~* [9 P7 a - //
- U6 Z+ B6 Z$ j- s7 U& M6 C# F" F - $wp = new WP();6 B1 c Z, o) u8 b2 M
- $wp->main();
3 k: {" I* @3 }- |* D - //4 [ @9 U& w0 J; R* Z2 b' ?
- $my_post = array();
( y: F8 ^9 B" _ - $my_post['post_title'] = $title;
- N2 y' R) p# N" f) `. B - $my_post['post_content'] = $content;$ d$ F1 w* e0 W" [8 F( |2 ^" C
- $my_post['post_status'] = 'publish';
! O8 \5 v, C2 z( V* p3 t - $my_post['post_author'] = 1; y' r6 F0 N7 A" t9 t, Y
- $my_post['post_category'] = array($cate);: v' q, `$ r: _+ a9 _/ K8 U
- $my_post['tags_input'] = $tags;
5 e! ^* o6 [& b8 ?) o - //$my_post['tags_input'] = array('tag1', 'tag2');: {- ~+ I# }- u5 T# p
- //$my_post['post_status'] = 'future';
2 }) c9 ?$ H$ \* g" W% ] - ////$my_post['post_date'] = '2010-07-04 16:20:03';
3 u9 @: z/ _! D) B4 D - ; @0 S8 S, l) q3 @0 a) l
- // Insert the post into the database! C' X% c& S. }% A* j
- $ret = wp_insert_post( $my_post );
3 t( S% p: B" W6 l" y$ t/ { - echo $ret;
! \6 k4 p6 {: v9 H9 D6 { - ?>
% A& W: A6 F) v0 o" P
复制代码 我自己写的# B1 G* L% n# ?# v3 M. d; }
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|