|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 g% r# l$ h, b; I4 [
$ H9 F& ?+ z) ~. R' E直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
) g# J0 @6 o9 c) }2 ?" L- m
/ z% }* N$ Z/ j7 d+ `3 X我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了 Y. n- U: P8 q2 R" d" }
/ a8 L3 {! r5 j7 |- V8 t1 H4 A
方便实用 简单 何乐而不用呢
- @( N' e- W: x* b: ?5 w# X1 r) |! ]- <?php: o% l. j, D/ l; f; P3 M( M$ R
- 7 o" B" T5 t ~% x: E$ A
- define( 'ABSPATH', dirname(__FILE__) . '/' );
# q3 O6 \2 b# W0 u, a/ a7 k! z - require_once( ABSPATH . 'wp-config.php' );
( j7 ~1 l. M) C+ Z- B5 \( z, l - require_once( ABSPATH . 'wp-settings.php' );9 s: j: K1 [6 y0 }! f- v, A
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
- }3 A# a& v4 R* W$ p9 u - require_once( ABSPATH . 'wp-includes/functions.php' );
. U' S' U7 e O$ V* ~ - require_once( ABSPATH . 'wp-includes/plugin.php' );4 _( ` q' N- N& e8 w" T2 u
- $title = $_POST["title"];
& }! l* {( j9 o* z1 K - $content = $_POST["content"];
. J0 i+ ~( ]+ |; D& b+ s - $tags = explode("_",$_POST["tags"]);* F5 i- L: P! n8 W7 k
- $cate = $_POST["cate"];
. ]& y7 w* p j4 e- T- g/ r: @& ~ - //print_r $tags;
! p8 f, ]# t* B5 N - // A6 Z9 h* Z, H$ ^& L c
- //- M; Q5 o( u+ b( _* n3 g$ J
- $wp = new WP();
7 x' \* n9 }& P9 V+ Q - $wp->main();; m g$ M7 }2 ]0 Y1 F. x
- //1 N" N' P- U* \1 X9 ^
- $my_post = array();$ P* D8 i; Q1 m/ u: X0 c' I
- $my_post['post_title'] = $title;
8 W" N/ V; s5 J: O& V - $my_post['post_content'] = $content;9 J$ a7 G0 P' U+ U: D$ G4 k! A
- $my_post['post_status'] = 'publish';
. v C) H5 n& y, b& d8 N r3 z. Y - $my_post['post_author'] = 1;. D5 \$ Y1 ^) A, [/ E6 y. D
- $my_post['post_category'] = array($cate);$ u- \5 G) Z6 Y
- $my_post['tags_input'] = $tags;
$ a4 G9 R- _& ?; w5 \0 y - //$my_post['tags_input'] = array('tag1', 'tag2');
* E. a. ^! P% |7 L# s - //$my_post['post_status'] = 'future';
5 l4 v5 N, K( R" D1 m0 C* T - ////$my_post['post_date'] = '2010-07-04 16:20:03';! N! O- c! M& b4 ~7 ?% j; j
- 7 x+ I6 p6 I+ y% t
- // Insert the post into the database5 i: g% p6 _# N
- $ret = wp_insert_post( $my_post );
; \6 S3 A( r4 ]7 ?0 Y - echo $ret;
6 N. I( y2 j6 @- N: Y5 G. |+ n! T4 r - ?>/ G& ?7 M' C1 W% D0 p; m
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
/ `0 x& P* A8 q+ k! M1 k, d, o- <?php# x, A ]* `5 T
- define( 'ABSPATH', dirname(__FILE__) . '/' );
4 a* B/ k) y- M+ w' n( m - require_once( ABSPATH . 'wp-config.php' );% b% t$ E. g' ~) K0 a# h) {
- require_once( ABSPATH . 'wp-settings.php' );
7 Z/ c0 U7 d8 Z& G - require_once( ABSPATH . 'wp-includes/class-wp.php' );
C7 j! W! g0 y, L& @9 r) ], z - require_once( ABSPATH . 'wp-includes/functions.php' );
) a; s2 \, @1 E$ V7 l g( R - require_once( ABSPATH . 'wp-includes/plugin.php' );( A8 G0 N6 @; u$ e: v' _, A) Q
- $pic_name = $_POST["pic_name"];" _5 ?7 _$ n4 g* s$ w1 U
- $pic = $_POST["pic"];5 Q* S) O7 F1 g
- if($pic != "" && $pic_name != ""): _) F! H9 }* J' \- E* B7 s# n
- {
8 l7 o$ }1 O: c3 @1 o5 @ - $path = "images/";: S) n \4 o I: ~
- $pic_name = $path.$pic_name;. T# n+ Z$ B+ {+ W6 A7 H/ N
- echo $pic_name;$ `9 g% T, R/ v; o! A
- echo "||";
+ j! G' ?$ m3 w3 F% ~7 K& g# C& t - error_reporting(0);& K1 [% M5 ^. X* l/ e9 @( D+ r* N
- mkdir("images");
) Z% S. S% A* @) r4 x - $handle = fopen($pic_name, 'w');9 r& D N6 o2 z1 W$ b) Q
- echo fwrite($handle,file_get_contents($pic));9 M7 H% l4 d5 |; z# \3 W1 q/ b
- } P ?9 T' G- T! G( z( n5 R9 e
' A5 }6 N+ H( r) N, r; Y- $title = $_POST["title"];
/ i1 X3 m" w I! m9 x9 [ - $content = $_POST["content"];- T" h' [- n! @ C! F* M
- $tags = explode("_",$_POST["tags"]);
5 t1 ^% d! l, G ~8 x. S - $cate = $_POST["cate"];" W& a' r6 d4 }" T' _
- //print_r $tags;# O6 _# u* W. j# B, w! Y
- //
" G" v3 a4 f8 |: Q& j - //" }7 X; `( P2 O8 Q, `& C2 y
- $wp = new WP();
) V) C' B$ B) G s( ]' X+ Y - $wp->main();
' ]! X0 \! r, i7 C - //7 `& H/ E* f2 o1 T
- $my_post = array();
" O" v5 K) U. c! E+ r - $my_post['post_title'] = $title;
) F. }2 P0 ?! Q - $my_post['post_content'] = $content;
/ `. J9 H! _; j! }; z - $my_post['post_status'] = 'publish';
/ ~$ l6 V3 {6 m3 B - $my_post['post_author'] = 1;
1 N1 m$ j8 q7 H& P - $my_post['post_category'] = array($cate);
8 M6 k' ~) k) m" l' C( \; S - $my_post['tags_input'] = $tags;2 R$ D* `' I% ]! k2 d" q- o
- //$my_post['tags_input'] = array('tag1', 'tag2');2 g3 ~5 y1 R; t' W+ G
- //$my_post['post_status'] = 'future';8 d* ~0 \; m7 S; J
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
& \3 \- h J; P4 F- [$ w
8 A; Y5 N5 K0 A+ i- // Insert the post into the database; w( b% ]* C9 u1 m" M# N
- $ret = wp_insert_post( $my_post );* W; I) c+ r) B
- echo $ret;
7 j& {& |% E! m1 x) K& d ] - ?>
4 m% a4 x- P( ~& x1 v' H# L
复制代码 我自己写的/ h2 M* @6 Z+ N- j
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|