|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 + [0 {( ] W8 f! |1 x9 z0 w
9 c+ p, o9 z7 R$ q" w直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
+ V: G m. q9 o6 ~1 g
% X. ]* i/ g$ A+ B4 Q我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了$ W" I& g. v6 I" _1 G7 G
( @9 V! T3 o2 ]3 N$ Z( `/ b* l5 M
方便实用 简单 何乐而不用呢
; J5 O1 K: D1 k- ?" r1 B2 d$ U- <?php; q* `8 k# i0 S$ y5 }! \3 @
- - P) r' t: u6 h3 ]* h
- define( 'ABSPATH', dirname(__FILE__) . '/' );1 u% \! z: F1 i) m6 X$ }1 k; H
- require_once( ABSPATH . 'wp-config.php' );$ y/ r8 D- `6 O ~/ \
- require_once( ABSPATH . 'wp-settings.php' );% |# f5 L C' @; B
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
5 e, A6 u: e) ~ - require_once( ABSPATH . 'wp-includes/functions.php' );
9 P3 ]0 @( V! L, p& p - require_once( ABSPATH . 'wp-includes/plugin.php' );0 b( q$ l1 w/ H
- $title = $_POST["title"];6 }8 z# Z1 k' f6 e% l$ U
- $content = $_POST["content"];
; r: i7 ]! c0 g+ t4 u - $tags = explode("_",$_POST["tags"]);8 W' R$ W+ M8 x8 D. H/ h, ]) z
- $cate = $_POST["cate"];
5 C2 P- g2 E/ `* a. e1 k. l - //print_r $tags;
. e5 v. U- x0 o - //
$ b% z$ k* _0 M1 g5 ~ - //: f4 D# w+ _" h; f5 K# ^ H* X
- $wp = new WP();8 m: F' I4 I, U6 _
- $wp->main();1 G! y# o& a% A7 j6 Y) E6 a
- //
* t% N; G* u0 R. M) Z/ d1 n. U - $my_post = array();
- y$ l+ S" o+ A5 _8 h+ b - $my_post['post_title'] = $title; u# s! z5 w# F( ^$ C- Y( v. T
- $my_post['post_content'] = $content;
d7 b. q q& ~$ ~, Y& U - $my_post['post_status'] = 'publish';9 |) {* \$ X! }5 s* R" ?$ [
- $my_post['post_author'] = 1;
. x; Z" m: o9 U5 y k* ~% g2 g+ A - $my_post['post_category'] = array($cate);
5 ]5 \/ X0 O: O3 K' }' v - $my_post['tags_input'] = $tags;- Y/ N: t$ o5 n6 Z' w
- //$my_post['tags_input'] = array('tag1', 'tag2');
# \4 _7 T; _4 R/ D- u8 y, }# W - //$my_post['post_status'] = 'future';9 P! k, ]/ K$ m: V0 M) j
- ////$my_post['post_date'] = '2010-07-04 16:20:03';- h% I# X' Z6 R# Z* Y* l$ r
- ; y8 |8 N3 b) W) |+ H. }
- // Insert the post into the database
/ A8 n: b7 F3 k4 U& m4 x/ } - $ret = wp_insert_post( $my_post );% v9 ^; k. Z& L4 Y0 N0 W
- echo $ret;
" }# c. T2 l5 c - ?>1 s: H6 X& f0 z
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
6 @0 a! H8 V) I! m$ U- <?php
9 u ~, u+ R" w9 j- n! Q- C - define( 'ABSPATH', dirname(__FILE__) . '/' );
- S# v0 R0 s4 E, L" o5 D - require_once( ABSPATH . 'wp-config.php' );9 ?/ M u7 a4 t! }" @
- require_once( ABSPATH . 'wp-settings.php' );0 r# e& \, s- \
- require_once( ABSPATH . 'wp-includes/class-wp.php' );% R/ m4 V5 \ L4 }* b$ r& p
- require_once( ABSPATH . 'wp-includes/functions.php' );" c9 e* m1 e9 D# D4 f2 S
- require_once( ABSPATH . 'wp-includes/plugin.php' );" [7 u/ [0 O, s
- $pic_name = $_POST["pic_name"];2 R; Z. d u1 _6 v- q- X
- $pic = $_POST["pic"];9 _; c! ?( ]7 E/ N) x) B) S4 Q. S
- if($pic != "" && $pic_name != "")
# ~9 \% H* n6 Z, ^) V. s. h5 d) R - {, F' r8 f# N& Y, z* W0 U
- $path = "images/";- q0 d4 Z8 U0 [+ K
- $pic_name = $path.$pic_name;
% M; `5 k% @6 m% o) E# p - echo $pic_name;
$ [/ r6 F( [; [! U# E: Y! m - echo "||";0 X$ u/ B# l; |$ S( G
- error_reporting(0);; a2 E* b' @% V" K. @# n- q
- mkdir("images");3 o, u$ h6 b/ e& k
- $handle = fopen($pic_name, 'w');# j, v# v' g: P1 a
- echo fwrite($handle,file_get_contents($pic));
* }6 ]" g. I: @/ @# x - }$ j. _: H. V! S+ n5 E
- 5 k! {' o6 @! m% }4 z
- $title = $_POST["title"];7 ~9 F/ C& | r5 o4 U& d
- $content = $_POST["content"];
/ K& a1 S# G: F* o+ M7 H - $tags = explode("_",$_POST["tags"]);
* e& o: s( f, M. a - $cate = $_POST["cate"]; D7 W, e' I3 e* i) I7 e9 I8 V
- //print_r $tags;
, n. N8 C& O3 j. n* x - //
: \- Q U1 g+ |! G8 y) C9 [ - //
9 h. r: n- O1 ]6 [- j - $wp = new WP();2 M: y2 L9 Y0 Q8 N/ K
- $wp->main();
/ m) M( L: z0 b, A" `$ @1 i - //
" J) a2 Z' @% R5 i' p' G( G) l# P - $my_post = array();
& j" n2 d( \+ I/ R# W5 M6 _ - $my_post['post_title'] = $title;9 L; i4 `% @& U6 v6 C& t1 F
- $my_post['post_content'] = $content;
1 Y X) o: Y5 A - $my_post['post_status'] = 'publish';9 }$ _ F& i1 G+ O
- $my_post['post_author'] = 1;: p3 v% c) ~3 ]# u
- $my_post['post_category'] = array($cate);3 k! C* A2 ]4 X" m) @5 i
- $my_post['tags_input'] = $tags;$ z( P1 j& u, P5 P. F# n
- //$my_post['tags_input'] = array('tag1', 'tag2');
9 @$ M9 I; x+ v# J - //$my_post['post_status'] = 'future';
7 ^) _# I+ h! U: z" L% W2 N - ////$my_post['post_date'] = '2010-07-04 16:20:03';
+ [0 Q6 X7 w7 k6 J& c
; x! ?: ^8 d1 L4 o1 p- // Insert the post into the database2 A3 H- u- d: N9 r' _
- $ret = wp_insert_post( $my_post );2 q4 M5 H6 `$ \& {
- echo $ret;
$ A; ^6 h; B( s P6 F% N) g K - ?>
! ^; M F5 f H7 P& I% Z
复制代码 我自己写的
' [0 N6 E& f+ a8 O7 H! B# g插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|